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

Chayandas07 patch 1 10 #24

Open
wants to merge 165 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
61fdd29
Create 17 NOV Count of Subarrays
Chayandas07 Nov 16, 2022
1ab19d0
Merge pull request #2 from Chayandas07/patch-1
Michael-Calce Nov 16, 2022
6caa51e
Create 18 NOV Number Of Open Doors
Chayandas07 Nov 18, 2022
393f2a4
Create 19 November Check if all levels of two trees are anagrams or not
Chayandas07 Nov 19, 2022
7ede2e6
Create 20 November LCM Triplet
Chayandas07 Nov 20, 2022
32913e1
Create 21 November Unique partitions
Chayandas07 Nov 21, 2022
e8932fb
Merge pull request #3 from Chayandas07/patch-2
Michael-Calce Nov 22, 2022
029a65c
Merge pull request #4 from Chayandas07/patch-3
Michael-Calce Nov 22, 2022
cfa8ba9
Merge pull request #5 from Chayandas07/patch-4
Michael-Calce Nov 22, 2022
649fa9c
Merge pull request #6 from Chayandas07/patch-5
Michael-Calce Nov 22, 2022
98b03e6
Create 23 NOV 23 November Maximum Sum LCM
Chayandas07 Nov 23, 2022
d93b55c
Create 4 November Longest Bitonic subsequence
Chayandas07 Nov 23, 2022
8f82c84
Merge pull request #8 from Chayandas07/patch-7
Michael-Calce Nov 27, 2022
62fa7ab
Merge pull request #7 from Chayandas07/patch-6
Michael-Calce Nov 27, 2022
00753dd
Create 28 NOV 28 November Maximum Sub Array
Chayandas07 Nov 27, 2022
fd12183
Merge pull request #9 from Chayandas07/patch-8
Michael-Calce Dec 1, 2022
4a9047a
Create 03 December Aggressive Cows
Chayandas07 Dec 3, 2022
0591ddd
Merge pull request #10 from Chayandas07/patch-9
Michael-Calce Dec 3, 2022
e99820a
Create 4 DEC 04 December Alternate Vowel and Consonant String
Chayandas07 Dec 4, 2022
033ea9a
Create 05 December Shortest Path by Removing K walls
Chayandas07 Dec 5, 2022
d9de051
06 December Distance of nearest cell having 1
Chayandas07 Dec 6, 2022
955b9c9
Create 08 December 3 Divisors
Chayandas07 Dec 8, 2022
5fd8101
Create 09 December Black and White
Chayandas07 Dec 9, 2022
d5f895c
Create 10 December Build the smallest
Chayandas07 Dec 9, 2022
b6a0b3d
Create 11 December Array Pair Sum Divisibility Problem
Chayandas07 Dec 10, 2022
ca85b0f
Create 12 December Articulation Point - I
Chayandas07 Dec 12, 2022
6783dd7
Create 13 December Split Array Largest Sum
Chayandas07 Dec 13, 2022
ed84c16
Create 14 December Complement
Chayandas07 Dec 14, 2022
b6a6706
Create 15 December Balanced string
Chayandas07 Dec 15, 2022
b898ba1
Create 16 December 2D Hopscotch
Chayandas07 Dec 15, 2022
41dd0ee
Create 17 December Break a number
Chayandas07 Dec 16, 2022
95ac689
Create 18 December A Game of LCM
Chayandas07 Dec 18, 2022
7307095
Create 19 December Alex Travelling
Chayandas07 Dec 19, 2022
0fcfb85
Create 20 December A difference of values and indexes
Chayandas07 Dec 20, 2022
35db673
Create 21 December Absolute List Sorting
Chayandas07 Dec 21, 2022
ce284e0
Merge pull request #11 from Chayandas07/patch-10
Michael-Calce Dec 21, 2022
2efabec
Merge pull request #12 from Chayandas07/patch-11
Michael-Calce Dec 21, 2022
e704ef4
Merge pull request #13 from Chayandas07/patch-12
Michael-Calce Dec 21, 2022
07d367d
Merge pull request #14 from Chayandas07/patch-14
Michael-Calce Dec 21, 2022
f7f1ffc
Merge pull request #15 from Chayandas07/patch-15
Michael-Calce Dec 21, 2022
e423df4
Merge pull request #16 from Chayandas07/patch-16
Michael-Calce Dec 21, 2022
6ff9b0b
Merge pull request #17 from Chayandas07/patch-17
Michael-Calce Dec 21, 2022
2e1b215
Create 22 December Zero Sum Subarrays
Chayandas07 Dec 22, 2022
a969917
Create 23 December Burst Balloons
Chayandas07 Dec 23, 2022
66ac192
Create 24 December Wine Buying and Selling
Chayandas07 Dec 24, 2022
1320b43
Create 25 December Missing number in matrix
Chayandas07 Dec 24, 2022
8db7447
Create 27 December Container With Most Water
Chayandas07 Dec 26, 2022
7a5c7b1
Create 28 December Largest subtree sum in a tree
Chayandas07 Dec 28, 2022
cb735b2
Create 2nd 30 December Single valued subtree
Chayandas07 Dec 30, 2022
e6223dd
Create 1st 30 December Single valued subtree
Chayandas07 Dec 30, 2022
c222e63
Create 31 December Find minimum number of Laptops required
Chayandas07 Dec 30, 2022
9203f23
Create 01 January Count even length(T)
Chayandas07 Jan 1, 2023
ebcfca2
Create 02 January Maximum Value
Chayandas07 Jan 2, 2023
caadaca
Create 03 January Minimize number of Students to be removed
Chayandas07 Jan 3, 2023
9f0d6ce
Create 04 January Maximum Profit By Choosing A Subset Of Intervals
Chayandas07 Jan 3, 2023
3421c25
Create 05 January Find the longest string
Chayandas07 Jan 5, 2023
359eea2
Create 07 January Flattening a Linked List
Chayandas07 Jan 7, 2023
dfca6ad
Create 08 January Absolute difference divisible by K
Chayandas07 Jan 8, 2023
137ab13
Create 10 January Transform to Sum Tree
Chayandas07 Jan 9, 2023
b09b759
Create 11 January Make array elements unique
Chayandas07 Jan 10, 2023
d1a6a93
Create 13 January Count Lucky Permutations
Chayandas07 Jan 13, 2023
3009655
Create 14 January Maximum Number of Toys
Chayandas07 Jan 14, 2023
a431f14
Create 15 January Count the Substring
Chayandas07 Jan 15, 2023
661563d
Create 16 January Next Greater Element
Chayandas07 Jan 16, 2023
8d8d0ad
Create 17 jan OO 926. Flip String to Monotone Increasing
Chayandas07 Jan 17, 2023
cadf399
Create 17 January Find the maximum GCD of the siblings of a Binary Tree
Chayandas07 Jan 17, 2023
562eb69
Create 18 January Find the first node of loop in linked list
Chayandas07 Jan 18, 2023
b969de5
Create 19 January Carpet into Box
Chayandas07 Jan 19, 2023
4874988
Create 20 January Maximum Weight Node
Chayandas07 Jan 20, 2023
6a41763
Create 21 January Minimum X (xor) A
Chayandas07 Jan 21, 2023
270bfbc
Create 22 January GCD Array
Chayandas07 Jan 22, 2023
4615b78
Create 23 January Geeks And The String
Chayandas07 Jan 23, 2023
02e6157
Create 24 January Convert an array to reduced form
Chayandas07 Jan 24, 2023
3c407fa
Create 25 January Type it!
Chayandas07 Jan 25, 2023
ee77d8c
Create 26 January Case-specific Sorting of Strings
Chayandas07 Jan 26, 2023
6a8729a
Create v.i.p 27 January Total Decoding Messages
Chayandas07 Jan 27, 2023
12b1c31
Create v 27 January Total Decoding Messages
Michael-Calce Jan 27, 2023
5b2b052
Merge pull request #62 from Michael-Calce/Michael-Calce-patch-2
Michael-Calce Jan 27, 2023
0c0b27e
Create 28 January Scrambled String
Chayandas07 Jan 28, 2023
e9b0282
Create 29 January Min operations
Chayandas07 Jan 29, 2023
ccf5f03
Create 30 January Select Nodes
Chayandas07 Jan 30, 2023
8f3376c
Create 31 January Minimum times A has to be repeated such that B is …
Chayandas07 Jan 31, 2023
01bfe82
Create 01 February Distinct Coloring
Chayandas07 Feb 1, 2023
dbd5d83
Create 02 February Largest Sum Cycle
Chayandas07 Feb 2, 2023
28aa30a
Create 03 February Last cell in a Matrix
Chayandas07 Feb 3, 2023
d132137
Create 04 February Max Sum without Adjacents
Chayandas07 Feb 4, 2023
4217ace
Create v.i.i 05 February Intersection Point in Y Shaped Linked Lists
Chayandas07 Feb 5, 2023
591fc83
Create 07 February Length of the longest subarray with positive product
Chayandas07 Feb 7, 2023
e0cc580
Create 08 February Count number of free cell
Chayandas07 Feb 8, 2023
626f113
Create 09 February Maximum Bipartite Matching
Chayandas07 Feb 9, 2023
20924e7
Create 10 February Balloon Everywhere
Chayandas07 Feb 10, 2023
32bfe44
Create 11 February Minimum Days
Chayandas07 Feb 11, 2023
e5dd788
Create 12 February Prime List
Chayandas07 Feb 12, 2023
b7bdcb2
Create 13 February Arithmetic Number
Chayandas07 Feb 13, 2023
8aa1713
Create 14 February Walls Coloring
Chayandas07 Feb 14, 2023
d9f281a
Create 15 February Geeks Island
Chayandas07 Feb 15, 2023
1206239
Create 16 February Good Stones
Chayandas07 Feb 16, 2023
eb80f2d
Create 17 February Is it Fibonacci
Chayandas07 Feb 17, 2023
c08c31f
Merge pull request #82 from Chayandas07/patch-81
Michael-Calce Feb 17, 2023
7307bbb
Merge pull request #81 from Chayandas07/patch-80
Michael-Calce Feb 17, 2023
00fbfac
Merge pull request #80 from Chayandas07/patch-79
Michael-Calce Feb 17, 2023
7a079cd
Merge pull request #79 from Chayandas07/patch-78
Michael-Calce Feb 17, 2023
40ade1a
Merge pull request #77 from Chayandas07/patch-76
Michael-Calce Feb 17, 2023
bc597f3
Merge pull request #78 from Chayandas07/patch-77
Michael-Calce Feb 17, 2023
2b5579f
Merge pull request #76 from Chayandas07/patch-75
Michael-Calce Feb 17, 2023
b09d65b
Merge pull request #75 from Chayandas07/patch-74
Michael-Calce Feb 17, 2023
a7bd50a
Merge pull request #74 from Chayandas07/patch-73
Michael-Calce Feb 17, 2023
c028c50
Merge pull request #73 from Chayandas07/patch-72
Michael-Calce Feb 17, 2023
2b01f97
Merge pull request #72 from Chayandas07/patch-71
Michael-Calce Feb 17, 2023
cc3c58b
Merge pull request #71 from Chayandas07/patch-70
Michael-Calce Feb 17, 2023
0f4c6d9
Merge pull request #70 from Chayandas07/patch-69
Michael-Calce Feb 17, 2023
f33bc3d
Merge pull request #69 from Chayandas07/patch-68
Michael-Calce Feb 17, 2023
98845ef
Merge pull request #68 from Chayandas07/patch-67
Michael-Calce Feb 17, 2023
023e324
Merge pull request #67 from Chayandas07/patch-66
Michael-Calce Feb 17, 2023
59fb393
Merge pull request #66 from Chayandas07/patch-65
Michael-Calce Feb 17, 2023
adf0141
Merge pull request #65 from Chayandas07/patch-64
Michael-Calce Feb 17, 2023
20cabeb
Merge pull request #64 from Chayandas07/patch-63
Michael-Calce Feb 17, 2023
95dd736
Merge pull request #63 from Chayandas07/patch-62
Michael-Calce Feb 17, 2023
fdb944e
Merge pull request #61 from Chayandas07/patch-61
Michael-Calce Feb 17, 2023
57746ac
Merge pull request #60 from Chayandas07/patch-60
Michael-Calce Feb 17, 2023
199091c
Merge pull request #59 from Chayandas07/patch-59
Michael-Calce Feb 17, 2023
9ab27f8
Merge pull request #58 from Chayandas07/patch-58
Michael-Calce Feb 17, 2023
ed45163
Merge pull request #57 from Chayandas07/patch-57
Michael-Calce Feb 17, 2023
31af816
Merge pull request #56 from Chayandas07/patch-56
Michael-Calce Feb 17, 2023
e85667f
Merge pull request #55 from Chayandas07/patch-55
Michael-Calce Feb 17, 2023
4068193
Merge pull request #54 from Chayandas07/patch-54
Michael-Calce Feb 17, 2023
d24c2a7
Merge pull request #53 from Chayandas07/patch-53
Michael-Calce Feb 17, 2023
cad3025
Merge pull request #52 from Chayandas07/patch-52
Michael-Calce Feb 17, 2023
6e1a64a
Merge pull request #51 from Chayandas07/patch-51
Michael-Calce Feb 17, 2023
112d26a
Merge pull request #50 from Chayandas07/patch-50
Michael-Calce Feb 17, 2023
4c3c016
Merge pull request #49 from Chayandas07/patch-49
Michael-Calce Feb 17, 2023
f2a274b
Merge pull request #48 from Chayandas07/patch-48
Michael-Calce Feb 17, 2023
d8f6f4e
Merge pull request #47 from Chayandas07/patch-47
Michael-Calce Feb 17, 2023
ed3b0c6
Merge pull request #46 from Chayandas07/patch-46
Michael-Calce Feb 17, 2023
bac3c4e
Merge pull request #45 from Chayandas07/patch-45
Michael-Calce Feb 17, 2023
f5b1506
Merge pull request #44 from Chayandas07/patch-44
Michael-Calce Feb 17, 2023
b0cc0e4
Merge pull request #43 from Chayandas07/patch-43
Michael-Calce Feb 17, 2023
2d00146
Merge pull request #42 from Chayandas07/patch-42
Michael-Calce Feb 17, 2023
367ead7
Merge pull request #41 from Chayandas07/patch-41
Michael-Calce Feb 17, 2023
a8b86f1
Merge pull request #40 from Chayandas07/patch-40
Michael-Calce Feb 17, 2023
4ef7a42
Merge pull request #39 from Chayandas07/patch-39
Michael-Calce Feb 17, 2023
3eb4b6a
Merge pull request #38 from Chayandas07/patch-38
Michael-Calce Feb 17, 2023
90bd639
Merge pull request #37 from Chayandas07/patch-37
Michael-Calce Feb 17, 2023
7548faa
Merge pull request #36 from Chayandas07/patch-36
Michael-Calce Feb 17, 2023
76774fb
Merge pull request #35 from Chayandas07/patch-35
Michael-Calce Feb 17, 2023
7359e4d
Merge pull request #34 from Chayandas07/patch-34
Michael-Calce Feb 17, 2023
5599833
Create 18 February Apple Sequences
Chayandas07 Feb 18, 2023
f451784
Merge pull request #83 from Chayandas07/patch-82
Michael-Calce Feb 18, 2023
2ae9126
Merge pull request #33 from Chayandas07/patch-33
Michael-Calce Feb 18, 2023
4762828
Merge pull request #32 from Chayandas07/patch-32
Michael-Calce Feb 18, 2023
22e56d7
Merge pull request #31 from Chayandas07/patch-31
Michael-Calce Feb 18, 2023
a197992
Merge pull request #30 from Chayandas07/patch-30
Michael-Calce Feb 18, 2023
19aff3f
Merge pull request #29 from Chayandas07/patch-29
Michael-Calce Feb 18, 2023
40c460d
Merge pull request #28 from Chayandas07/patch-28
Michael-Calce Feb 18, 2023
b0b500c
Merge pull request #27 from Chayandas07/patch-27
Michael-Calce Feb 18, 2023
e54071c
Merge pull request #26 from Chayandas07/patch-26
Michael-Calce Feb 18, 2023
97caf44
Merge pull request #25 from Chayandas07/patch-25
Michael-Calce Feb 18, 2023
5ca0f39
Merge pull request #24 from Chayandas07/patch-24
Michael-Calce Feb 18, 2023
d580dd5
Merge pull request #23 from Chayandas07/patch-23
Michael-Calce Feb 18, 2023
0b6bd62
Merge pull request #22 from Chayandas07/patch-22
Michael-Calce Feb 18, 2023
209d477
Merge pull request #21 from Chayandas07/patch-21
Michael-Calce Feb 18, 2023
80384df
Merge pull request #20 from Chayandas07/patch-20
Michael-Calce Feb 18, 2023
8c6f283
Merge pull request #19 from Chayandas07/patch-19
Michael-Calce Feb 18, 2023
ee8c778
Merge pull request #18 from Chayandas07/patch-18
Michael-Calce Feb 18, 2023
580563b
Create 10 May Total Cuts
Chayandas07 May 10, 2023
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
21 changes: 21 additions & 0 deletions 01 February Distinct Coloring
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution{
public:
long long int distinctColoring(int N, int r[], int g[], int b[]){
// code here
long long int dpr[N];
long long int dpg[N];
long long int dpb[N];
dpr[0]=r[0];
dpg[0]=g[0];
dpb[0]=b[0];

for(int i=1;i<N;i++){
dpr[i]=min(dpg[i-1],dpb[i-1])+r[i];
dpg[i]=min(dpr[i-1],dpb[i-1])+g[i];
dpb[i]=min(dpr[i-1],dpg[i-1])+b[i];
}
long long int mini=min(dpr[N-1],min(dpg[N-1],dpb[N-1]));
return mini;

}
};
43 changes: 43 additions & 0 deletions 01 January Count even length(T)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Solution{

public:

int inv(int n, int m, int mod=1000000007){

if(m==0) return 1;

if(m&1) return (n*1ll*inv(n, m-1))%mod;

int tmp=inv(n, m/2);

return (tmp*1ll*tmp)%mod;

}

int compute_value(int n)

{

// Code here

int m = 1000000007;

long long fact2N=1, factN;

for(int i=1; i<=2*n; i++){

fact2N *= i;

fact2N %= m;

if(i==n)factN=fact2N;

}

factN = (factN*factN)%m;

return (fact2N * 1ll * inv(factN, m-2))%m;

}

};
55 changes: 55 additions & 0 deletions 02 February Largest Sum Cycle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class Solution
{
public:
vector<vector<int>> v;
vector<int> vis,par,tmp;
long long dfs(int node,int p=-1){
vis[node]=1;
par[node]=p;
tmp.push_back(node);
for(auto i:v[node]){
if(vis[i]==0){
long long z=dfs(i,node);
if(z!=-1){
return z;
}
}
else if(vis[i]==1){
long long sum=i;
while(node!=i){
sum+=node;
node=par[node];
}
if(node==i)
return sum;
return -1;
}
}
return -1;
}
long long largestSumCycle(int N, vector<int> Edge)
{
long long ans=-1;
vis=vector<int>(N);
v=vector<vector<int>>(N);
par=vector<int>(N);

for(int i=0;i<N;i++){
if(Edge[i]!=-1){
v[i].push_back(Edge[i]);
}
}

for(int i=0;i<N;i++){
if(!vis[i]){
ans=max(ans,dfs(i));
for(auto j:tmp){
vis[j]=2;
}
tmp.clear();
}
}

return ans;
}
};
43 changes: 43 additions & 0 deletions 02 January Maximum Value
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Solution {
public:
void traverse(Node* node, vector<int>& ans, int level ){
if(node == NULL )
return;
if(ans.size()>=level){
ans[level-1] = max(node->data, ans[level-1]);
}
else{
ans.push_back(node->data);
}
traverse(node->left, ans, level+1);
traverse(node->right, ans, level+1);
}
// Takes O(n) Time complexity and O(H) space complexity
void dfs(Node* node, vector<int>&ans){
if (node==NULL)
return;
stack<pair<Node*, int>> s;
s.push({node, 1});
while(!s.empty()){
auto it = s.top();
s.pop();
if(ans.size()>=it.second){
ans[it.second-1] = max(it.first->data, ans[it.second-1]);
}
else{
ans.push_back(it.first->data);
}
if(it.first->left != NULL )
s.push({it.first->left, it.second+1});
if(it.first->right != NULL )
s.push({it.first->right, it.second+1});
}
}
vector<int> maximumValue(Node* node) {
vector<int> ans;
// int level = 1;
// traverse(node, ans, level);
dfs(node, ans);
return ans;
}
};
28 changes: 28 additions & 0 deletions 03 December Aggressive Cows
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public:

int solve(int n, int k, vector<int> &stalls) {
sort(stalls.begin(),stalls.end());
int l=0,r=stalls[n-1]-stalls[0];
int ans=0;
while(l<=r){
int mid=(l+r)/2;
int cow=1;
int last=stalls[0];
for(int i=1;i<n;i++){
if(stalls[i]-last>=mid){
cow++;
last=stalls[i];
}
}
if(cow>=k){
ans=mid;
l=mid+1;
}
else{
r=mid-1;
}
}
return ans;
}
};
24 changes: 24 additions & 0 deletions 03 February Last cell in a Matrix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution{
public:
pair<int,int> endPoints(vector<vector<int>> matrix, int R, int C){
//code here
int x=0;
int y=0;
int dir =0;
int dirx[] = {0,1,0,-1};
int diry[] = {1,0,-1,0};
while(x>=0 && y>=0 && x<R && y< C){
if(matrix[x][y]){
dir = (dir+1)%4;
matrix[x][y] =0;

}
x+=dirx[dir];
y += diry[dir];
}
pair<int,int> ans;
ans.first = x-dirx[dir];
ans.second = y-diry[dir];
return ans;
}
};
41 changes: 41 additions & 0 deletions 03 January Minimize number of Students to be removed
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Solution {
public:
// Helper function to find LIS
int LongestIncreasingSubsequenceLength(vector<int>& v)
{
if (v.size() == 0)
return 0;

vector<int> tail(v.size(), 0);
int length = 1; // always points empty slot in tail

tail[0] = v[0];

for (int i = 1; i < v.size(); i++) {

// Do binary search for the element in
// the range from begin to begin + length
auto b = tail.begin(), e = tail.begin() + length;
auto it = lower_bound(b, e, v[i]);

// If not present change the tail element to v[i]
if (it == tail.begin() + length)
tail[length++] = v[i];
else
*it = v[i];
}

return length;
}

int removeStudents(int H[], int N) {

vector<int> arr;
for(int i=0; i<N; i++)
arr.push_back(H[i]);

int ans = N - LongestIncreasingSubsequenceLength(arr);

return ans;
}
};
19 changes: 19 additions & 0 deletions 04 February Max Sum without Adjacents
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution{
public:
// calculate the maximum sum with out adjacent
int findMaxSum(int *arr, int n) {
if(n==1) return arr[0];
int a=arr[0];

int b=max(arr[0],arr[1]);
int curr=0;
for(int i=2;i<n;i++)
{
curr=max(b,arr[i]+a);
a=b;
b=curr;

}
return max(a,b);
}
};
30 changes: 30 additions & 0 deletions 04 January Maximum Profit By Choosing A Subset Of Intervals
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution {
public:
vector<vector<int>>job;
int p=0;
int solve(int i,vector<int>&dp,vector<int>&startTime){
if(i>=job.size())return 0;
if(dp[i]!=-1)return dp[i];
int next=lower_bound(startTime.begin(),startTime.end(),job[i][1])-startTime.begin();
return dp[i]=max(solve(i+1,dp,startTime),job[i][2]+solve(next,dp,startTime));
}
int jobSched(vector<int>& startTime, vector<int>& endTime, vector<int>& profit) {
for(int i=0;i<startTime.size();i++){
job.push_back({startTime[i],endTime[i],profit[i]});
}
sort(job.begin(),job.end());
sort(startTime.begin(),startTime.end());
vector<int>dp(job.size(),-1);
return solve(0,dp,startTime);
}
int maximum_profit(int n, vector<vector<int>> &in) {
// Write your code here.
vector<int>s,e,p;
for(int i=0;i<n;i++){
s.push_back(in[i][0]);
e.push_back(in[i][1]);
p.push_back(in[i][2]);
}
return jobSched(s,e,p);
}
};
35 changes: 35 additions & 0 deletions 05 December Shortest Path by Removing K walls
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Solution {
public:
int shotestPath(vector<vector<int>> mat, int n, int m, int k) {
vector<vector<int>> lives(n, vector<int> (m, -1));
queue<vector<int>> q;
// q-> row, col, k, dist
q.push({0, 0, k, 0});

int dx[] = {-1, 0, 1, 0, -1};
while(!q.empty()) {
vector<int> temp = q.front();
q.pop();

int row = temp[0];
int col = temp[1];
int clives = temp[2];
int dist = temp[3];

if(row == n-1 && col == m-1) return dist;

if(mat[row][col] == 1) clives--;

for(int i=0; i<4; i++) {
int nrow = row + dx[i];
int ncol = col + dx[i+1];

if(nrow >= 0 && nrow < n && ncol >= 0 && ncol < m && lives[nrow][ncol] < clives) {
q.push({nrow, ncol, clives, dist+1});
lives[nrow][ncol] = clives;
}
}
}
return -1;
}
};
39 changes: 39 additions & 0 deletions 05 January Find the longest string
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Solution
{
public:
string longestString(vector<string> &words)
{
sort(words.begin(),words.end(),[&](string &a,string &b){
return a.size()<b.size();
});
string ans="";
set<string>s(words.begin(),words.end());
for(int i=0;i<words.size();i++)
{
string a=words[i];
string word="";
int c=0;
for(int j=0;j<a.length();j++)
{
word+=a[j];
if(s.find(word)==s.end())
break;
else
c++;
}
if(c==a.length())
{
if(ans.length()!=c)
{
ans=a;
}
else if(ans.length()==c)
{
if(ans>a)
ans=a;
}
}
}
return ans;
}
};
Loading