Skip to content

Add OST_contribution files and tream #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions OST_contribution/line_reflection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
#include <vector>
#include <unordered_set>
#include<climits>

using namespace std;

class Solution {
public:
bool isReflected(vector<vector<int>>& points) {
int min_x = INT_MAX, max_x = INT_MIN;
unordered_set<string> 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<vector<int>> 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;
}
44 changes: 44 additions & 0 deletions OST_contribution/max_dist_to _closest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int maxDistToClosest(std::vector<int>& 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 :"<<endl;
cin>>n;
std::vector<int> seats(n);
cout<<"Enter the status of the seats(0 for empty and 1 for occupied):"<<endl;
for(int i=0;i<n;i++)
{
cin>>seats[i];
}
std::cout << "Maximum Distance to Closest Person: " << maxDistToClosest(seats) << std::endl;
return 0;
}
59 changes: 59 additions & 0 deletions tream
Original file line number Diff line number Diff line change
@@ -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