diff --git a/Day-15/q3-Longest Increasing Subsequence/Shubh_Krishna_solution.cpp b/Day-15/q3-Longest Increasing Subsequence/Shubh_Krishna_solution.cpp new file mode 100644 index 00000000..cd3a6298 --- /dev/null +++ b/Day-15/q3-Longest Increasing Subsequence/Shubh_Krishna_solution.cpp @@ -0,0 +1,15 @@ +int lengthOfLIS(vector& nums) { + int n=nums.size(); + int lis[n]; + lis[0]=1; + for(int i=1;inums[j] && lis[i]& 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]||tnums[n]){ + r=mid-1; + }else{ + l=mid+1; + } + } + } + + return -1; +} diff --git a/Day-22/q2: Sum of Left Leaves/Shubh_Krishna_solution.cpp b/Day-22/q2: Sum of Left Leaves/Shubh_Krishna_solution.cpp new file mode 100644 index 00000000..77ebd089 --- /dev/null +++ b/Day-22/q2: Sum of Left Leaves/Shubh_Krishna_solution.cpp @@ -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; +} diff --git a/Day-26/q2: Score of Parentheses/Shubh_Krishna_solution.cpp b/Day-26/q2: Score of Parentheses/Shubh_Krishna_solution.cpp new file mode 100644 index 00000000..1c218d5a --- /dev/null +++ b/Day-26/q2: Score of Parentheses/Shubh_Krishna_solution.cpp @@ -0,0 +1,14 @@ +int scoreOfParentheses(string S) { + stack 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; +}