Skip to content
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

Day 15 q3 & Day 22 q2 & Day 18 Q2 & Day 17 q1 & Day 26 q2 Completed #595

Merged
merged 24 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
71dabb2
Create solution.cpp
Shubh-Krishna Jan 25, 2024
0a7e51f
Update solution.cpp
Shubh-Krishna Jan 25, 2024
30410db
Update solution.cpp
Shubh-Krishna Jan 25, 2024
8655bb6
Update solution.cpp
Shubh-Krishna Jan 25, 2024
9f60c13
Create solution.cpp
Shubh-Krishna Jan 25, 2024
84ce528
Update solution.cpp
Shubh-Krishna Jan 25, 2024
90abe27
Update solution.cpp
Shubh-Krishna Jan 25, 2024
59c440b
Update solution.cpp
Shubh-Krishna Jan 25, 2024
d353736
Update solution.cpp
Shubh-Krishna Jan 25, 2024
0bf7802
Create Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
f12c5c4
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
f775470
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
e83da94
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
9c904fa
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
61f3fc5
Rename solution.cpp to Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
d46fc4e
Rename solution.cpp to Subh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
5cafb96
Create Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
141d6ec
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
0ffcf6c
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
359728e
Create Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
c62b8b0
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
c39124f
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
ad9b0ab
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
6471ccf
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 25, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
int lengthOfLIS(vector<int>& nums) {
int n=nums.size();
int lis[n];
lis[0]=1;
for(int i=1;i<n;i++)
{
lis[i]=1;
for(int j=0;j<i;j++){
if(nums[i]>nums[j] && lis[i]<lis[j]+1)
lis[i]=lis[j]+1;
}
}
return *max_element(lis,lis+n);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bool closeStrings(string word1, string word2) {
int cnt1[26]{};
int cnt2[26]{};
for (char& c : word1) {
++cnt1[c - 'a'];
}
for (char& c : word2) {
++cnt2[c - 'a'];
}
for (int i = 0; i < 26; ++i) {
if ((cnt1[i] == 0) != (cnt2[i] == 0)) {
return false;
}
}
sort(cnt1, cnt1 + 26);
sort(cnt2, cnt2 + 26);
return equal(cnt1, cnt1 + 26, cnt2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
int search(vector<int>& nums, int t) {
int ans=0,l=0,r=nums.size()-1,mid=0;
int n=nums.size()-1;


while(l<=r){
mid=(l+r)/2;
if(t==nums[mid]){return mid;}
if(nums[mid]>nums[n]){
if(t>nums[mid]||t<nums[0]){
l=mid+1;
}else{
r=mid-1;
}
}else{
if(t<nums[mid]||t>nums[n]){
r=mid-1;
}else{
l=mid+1;
}
}
}

return -1;
}
13 changes: 13 additions & 0 deletions Day-22/q2: Sum of Left Leaves/Shubh_Krishna_solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
int sumOfLeftLeaves(struct TreeNode* root){
if (!root)
return 0;

int sum = 0;
if (root->left && !root->left->left && !root->left->right)
sum += root->left->val;

sum+=sumOfLeftLeaves(root->left);
sum+=sumOfLeftLeaves(root->right);

return sum;
}
14 changes: 14 additions & 0 deletions Day-26/q2: Score of Parentheses/Shubh_Krishna_solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int scoreOfParentheses(string S) {
stack<int> stack;
int cur = 0;
for (char i : S)
if (i == '(') {
stack.push(cur);
cur = 0;
}
else {
cur += stack.top() + max(cur, 1);
stack.pop();
}
return cur;
}