diff --git a/OST_contribution/line_reflection.cpp b/OST_contribution/line_reflection.cpp new file mode 100644 index 00000000..901d125e --- /dev/null +++ b/OST_contribution/line_reflection.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +using namespace std; + +class Solution { +public: + bool isReflected(vector>& points) { + int min_x = INT_MAX, max_x = INT_MIN; + unordered_set pointSet; + + // Find the min and max x-coordinates and store points in a set + for (const auto& point : points) { + min_x = min(min_x, point[0]); + max_x = max(max_x, point[0]); + pointSet.insert(to_string(point[0]) + "_" + to_string(point[1])); + } + + // Calculate the potential line of reflection + double mid = (min_x + max_x) / 2.0; + + // Check if every point has a corresponding reflected point + for (const auto& point : points) { + int reflected_x = 2 * mid - point[0]; + string reflectedPoint = to_string(reflected_x) + "_" + to_string(point[1]); + if (pointSet.find(reflectedPoint) == pointSet.end()) { + return false; + } + } + + return true; + } +}; + +int main() { + Solution sol; + vector> points = {{1, 1}, {-1, 1}, {3, 2}, {-3, 2}}; + if (sol.isReflected(points)) { + cout << "Points are symmetrical about a vertical line.\n"; + } else { + cout << "Points are not symmetrical.\n"; + } + return 0; +} diff --git a/OST_contribution/max_dist_to _closest.cpp b/OST_contribution/max_dist_to _closest.cpp new file mode 100644 index 00000000..939e9cd1 --- /dev/null +++ b/OST_contribution/max_dist_to _closest.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +using namespace std; + +int maxDistToClosest(std::vector& seats) { + int n = seats.size(); + int max_dist = 0; + int last_person = -1; + + // Pass 1: Calculate max distance for the empty seats before the first occupied seat and in between. + for (int i = 0; i < n; i++) { + if (seats[i] == 1) { + if (last_person == -1) { + // If this is the first person, the distance to the closest person for all previous seats is just `i`. + max_dist = i; + } else { + // Otherwise, for seats between two people, the max distance is half the gap. + max_dist = std::max(max_dist, (i - last_person) / 2); + } + last_person = i; + } + } + + // Pass 2: Calculate max distance for the empty seats after the last occupied seat. + max_dist = std::max(max_dist, n - 1 - last_person); + + return max_dist; +} + +int main() +{ + int n; + cout<<"Enter the total no. of seats :"<>n; + std::vector seats(n); + cout<<"Enter the status of the seats(0 for empty and 1 for occupied):"<>seats[i]; + } + std::cout << "Maximum Distance to Closest Person: " << maxDistToClosest(seats) << std::endl; + return 0; +} diff --git a/tream b/tream new file mode 100644 index 00000000..f2884b4f --- /dev/null +++ b/tream @@ -0,0 +1,59 @@ + + SSUUMMMMAARRYY OOFF LLEESSSS CCOOMMMMAANNDDSS + + Commands marked with * may be preceded by a number, _N. + Notes in parentheses indicate the behavior if _N is given. + A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K. + + h H Display this help. + q :q Q :Q ZZ Exit. + --------------------------------------------------------------------------- + + MMOOVVIINNGG + + e ^E j ^N CR * Forward one line (or _N lines). + y ^Y k ^K ^P * Backward one line (or _N lines). + f ^F ^V SPACE * Forward one window (or _N lines). + b ^B ESC-v * Backward one window (or _N lines). + z * Forward one window (and set window to _N). + w * Backward one window (and set window to _N). + ESC-SPACE * Forward one window, but don't stop at end-of-file. + d ^D * Forward one half-window (and set half-window to _N). + u ^U * Backward one half-window (and set half-window to _N). + ESC-) RightArrow * Right one half screen width (or _N positions). + ESC-( LeftArrow * Left one half screen width (or _N positions). + ESC-} ^RightArrow Right to last column displayed. + ESC-{ ^LeftArrow Left to first column. + F Forward forever; like "tail -f". + ESC-F Like F but stop when search pattern is found. + r ^R ^L Repaint screen. + R Repaint screen, discarding buffered input. + --------------------------------------------------- + Default "window" is the screen height. + Default "half-window" is half of the screen height. + --------------------------------------------------------------------------- + + SSEEAARRCCHHIINNGG + + /_p_a_t_t_e_r_n * Search forward for (_N-th) matching line. + ?_p_a_t_t_e_r_n * Search backward for (_N-th) matching line. + n * Repeat previous search (for _N-th occurrence). + N * Repeat previous search in reverse direction. + ESC-n * Repeat previous search, spanning files. + ESC-N * Repeat previous search, reverse dir. & spanning files. + ESC-u Undo (toggle) search highlighting. + ESC-U Clear search highlighting. + &_p_a_t_t_e_r_n * Display only matching lines. + --------------------------------------------------- + A search pattern may begin with one or more of: + ^N or ! Search for NON-matching lines. + ^E or * Search multiple files (pass thru END OF FILE). + ^F or @ Start search at FIRST file (for /) or last file (for ?). + ^K Highlight matches, but don't move (KEEP position). + ^R Don't use REGULAR EXPRESSIONS. + ^S _n Search for match in _n-th parenthesized subpattern. + ^W WRAP search if no match found. + --------------------------------------------------------------------------- + + JJUUMMPPIINNGG +