Skip to content

Commit

Permalink
Merge pull request #595 from Shubh-Krishna/main
Browse files Browse the repository at this point in the history
Day 15 q3 & Day 22 q2 & Day 18 Q2 & Day 17 q1 & Day 26 q2 Completed
  • Loading branch information
kratika-Jangid authored Jan 27, 2024
2 parents ae0b2b6 + 6471ccf commit c46d999
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
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;
}

0 comments on commit c46d999

Please sign in to comment.