Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
49eb9b2
Create Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
31f636e
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
64f1cad
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
738aef0
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
2fd87ba
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
4d5139a
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
1eb3494
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
4d978d6
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
c57f62e
Create Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
1868cbb
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
460819f
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
c776804
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
1b14e3a
Create Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
cc241ad
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
0a43aa5
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
c362131
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
4ba092c
Create Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
031b411
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
898c1a1
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
53926f4
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
4381d5b
Create Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
46d0351
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
619cfe3
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
17857c4
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 2024
a318325
Update Shubh_Krishna_solution.cpp
Shubh-Krishna Jan 27, 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
20 changes: 20 additions & 0 deletions Day-21/q3: Unique Paths/Shubh_Krishna_solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
int uniquePaths(int m, int n) {
vector<vector<int>> dp(m, vector<int>(n, -1));
return solve(m-1,n-1,dp);
}

int solve(int m,int n, vector<vector<int>> &dp){
if(m==0 && n==0){
return 1;
}
if(m<0 || n<0){
return 0;
}
if(dp[m][n]!=-1){
return dp[m][n];
}

int up=solve(m-1,n,dp);
int left=solve(m,n-1,dp);
return dp[m][n]=up+left;
}
36 changes: 36 additions & 0 deletions Day-22/q3: Sort List/Shubh_Krishna_solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ListNode *mergeList(ListNode *l1, ListNode *l2){
ListNode *prev=new ListNode(-1), *curr=prev;
while(l1 and l2){
if(l1->val<=l2->val){
curr->next=l1;
l1=l1->next;
}else{
curr->next=l2;
l2=l2->next;
}
curr=curr->next;
}
if(l1){
curr->next=l1;
l1=l1->next;
}
if(l2){
curr->next=l2;
l2=l2->next;
}
return prev->next;
}

ListNode* sortList(ListNode* head){
if(!head or !head->next) return head;
ListNode *slow=head, *fast=head, *temp=NULL;
while(fast and fast->next){
temp=slow;
slow=slow->next;
fast=fast->next->next;
}
temp->next=NULL;

ListNode *point1=sortList(head), *point2=sortList(slow);
return mergeList(point1,point2);
}
33 changes: 33 additions & 0 deletions Day-23/q1: Minimum falling path sum/Shubh_Krishna_solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
int minFallingPathSum(vector<vector<int>>& matrix) {
int n=matrix.size();
int m=matrix[0].size();
vector<vector<int>>dp(n,vector<int>(m,0));

for(int j=0;j<m;j++)
{
dp[0][j]=matrix[0][j];
}

for(int i=1;i<n;i++)
{
for(int j=0;j<m;j++)
{
int ld=1e9,rd=1e9;
int up=matrix[i][j] + dp[i-1][j];

if(j-1>=0)
ld=matrix[i][j] + dp[i-1][j-1];
if(j+1<m)
rd=matrix[i][j] + dp[i-1][j+1];

dp[i][j] = min(up,min(ld,rd));
}
}
int mini=dp[n-1][0];

for(int j=1;j<m;j++)
{
mini=min(mini,dp[n-1][j]);
}
return mini;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
int n = nums.size() - 1;
int low = 0;
int high = n;
int first = -1;
int last = -1;
while(high >= low){
int mid = low + (high - low) / 2;

if(nums[mid] == target){
if(mid == 0 || nums[mid - 1] != target){
first = last = mid;
break;
}else{
high = mid - 1;
}
}
else if(nums[mid] > target){
high = mid-1;
}else{
low = mid+1;
}
}

high = n;

while(high >= low){
int mid = low + (high - low) / 2;

if(nums[mid] == target){
if(mid == n || nums[mid + 1] != target){
last = mid;
break;
}else{
low = mid + 1;
}
}
else if(nums[mid] > target){
high = mid-1;
}else{
low = mid+1;
}
}
return {first, last};
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
int maxLength(vector<string>& arr) {
vector<int> dp = {0};
int res = 0;

for (const string& s : arr) {
int a = 0, dup = 0;
for (char c : s) {
dup |= a & (1 << (c - 'a'));
a |= 1 << (c - 'a');
}

if (dup > 0)
continue;

for (int i = dp.size() - 1; i >= 0; i--) {
if ((dp[i] & a) > 0)
continue;
dp.push_back(dp[i] | a);
res = max(res, __builtin_popcount(dp[i] | a));
}
}

return res;
}