Skip to content

Max_points_on_line/ #135

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

Open
wants to merge 148 commits into
base: revert-34-new-branch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
dbb474f
Create Median of Two Sorted ArmedianOfSortedArrays.cpp
harmanjit356 Oct 2, 2022
2d84ab1
Added 42. Trapping Rain Water in Java
llyram Oct 2, 2022
1fcedce
Merge pull request #36 from saritapatel8770/revert-34-new-branch
saritapatel8770 Oct 2, 2022
d0b44aa
Added java solution for leetcode problem of first missing positive.
ananya-1112 Oct 2, 2022
f48c807
Merge pull request #37 from Maryll-castelino/main
saritapatel8770 Oct 2, 2022
2baeb10
Merge pull request #33 from harmanjit356/patch-5
saritapatel8770 Oct 2, 2022
f5ad366
Create Surrounded_Regions_Leetcode.cpp
iamrishabhjoshi Oct 2, 2022
37952fa
https://leetcode.com/problems/find-median-from-data-stream/
Shikhar-24 Oct 2, 2022
9e027f7
Merge pull request #39 from iamrishabhjoshi/main
saritapatel8770 Oct 2, 2022
72e6cb0
Merge pull request #38 from ananya-1112/firstmissingpositive
saritapatel8770 Oct 2, 2022
a87a20d
Merge pull request #40 from Shikhar-24/main
saritapatel8770 Oct 2, 2022
b80ed6b
Create 140_Word_Break_II.cpp
iamrishabhjoshi Oct 2, 2022
733831f
Create 146_LRU_Cache.cpp
iamrishabhjoshi Oct 2, 2022
b366b90
Create Number_of_Dice_Rolls_With_Target_Sum.cpp
anonymousss-112 Oct 2, 2022
c65b401
Update longest_valid_parentheses.java
Gur-jot Oct 2, 2022
f8a2d84
added the solution
Indrajeet-S Oct 2, 2022
ba96a93
added code for combination_sum_II in python
Adiii1436 Oct 2, 2022
fd6ec7e
Merge branch 'saritapatel8770:main' into issue#4
Adiii1436 Oct 2, 2022
717fb45
Added optimal string partition in JS
NisargChokshi45 Oct 2, 2022
3992b56
Added solution of question 2415.(Reverse Odd Levels of Binary Tree)
roushan-rks Oct 2, 2022
da6688e
Leetcode Solution added
raazanand Oct 3, 2022
d6e8121
Create Reverse Odd Levels of Binary Tree in easiest way
Amanjaiswal-20 Oct 3, 2022
7abb65a
Merge pull request #51 from Amanjaiswal-20/main
saritapatel8770 Oct 3, 2022
f9b4929
Merge pull request #50 from raazanand/main
saritapatel8770 Oct 3, 2022
bd49e54
Merge pull request #49 from roushan-rks/main
saritapatel8770 Oct 3, 2022
069d144
Merge pull request #48 from NisargChokshi45/2405/adding-optimal-strin…
saritapatel8770 Oct 3, 2022
64244cd
Merge pull request #47 from Adiii1436/issue#4
saritapatel8770 Oct 3, 2022
62ad5e7
Merge pull request #46 from Indrajeet-S/sol
saritapatel8770 Oct 3, 2022
0900047
Merge pull request #44 from Gur-jot/patch-1
saritapatel8770 Oct 3, 2022
d42d912
Merge pull request #42 from anonymousss-112/main
saritapatel8770 Oct 3, 2022
71be45f
Merge pull request #41 from iamrishabhjoshi/main
saritapatel8770 Oct 3, 2022
1000df2
Add files via upload
vatsal9117 Oct 3, 2022
83a9c86
Create Merge-k-Sorted-Lists.cpp
lucy2512 Oct 3, 2022
0ef45ea
Create LRU-Cache.cpp
ShinchanTheMaster Oct 3, 2022
f639b0c
K Highest Ranked Items Within a Price Range cpp solution
yashkhandelwal2203 Oct 3, 2022
aa95a81
Update tapping rain water
yashkhandelwal2203 Oct 3, 2022
cdab651
Create Longest_Valid_Parentheses.java
Dhanshriborse Oct 3, 2022
593cce9
Create 140.-Word-Break-II.java
anirudh0806 Oct 3, 2022
462c08e
Merge pull request #1 from anirudh0806/140.-Word-Break-II
anirudh0806 Oct 3, 2022
3927edd
Added C++ solution to Optimal Partition of String Problem
Jay179-sudo Oct 3, 2022
5086753
Added Longest valid parentheses in JS
NisargChokshi45 Oct 3, 2022
258dfbb
Add 100. Same Tree solution
JohannesDev Oct 3, 2022
f7aec12
trapping rain water in java
00suryavanshi00 Oct 3, 2022
453c95a
Added Permutations in JS
NisargChokshi45 Oct 3, 2022
add63b8
Merge pull request #64 from NisargChokshi45/46/adding-permutation-JS
saritapatel8770 Oct 3, 2022
19877c2
Merge pull request #63 from 00suryavanshi00/solution
saritapatel8770 Oct 3, 2022
e02c091
Merge pull request #62 from JohannesDev/main
saritapatel8770 Oct 3, 2022
2ed6301
Merge pull request #60 from NisargChokshi45/32/longest-valid-paranthe…
saritapatel8770 Oct 3, 2022
cf14c81
Merge pull request #59 from Jay179-sudo/Optimal-Partition
saritapatel8770 Oct 3, 2022
d646976
Merge pull request #58 from anirudh0806/main
saritapatel8770 Oct 3, 2022
63c353b
Merge pull request #57 from Dhanshriborse/patch-2
saritapatel8770 Oct 3, 2022
1a7a625
Merge pull request #56 from yashkhandelwal2203/patch-1
saritapatel8770 Oct 3, 2022
b71047e
Merge pull request #55 from yashkhandelwal2203/main
saritapatel8770 Oct 3, 2022
5b2a88d
Merge pull request #54 from ShinchanTheMaster/main
saritapatel8770 Oct 3, 2022
6b0abda
Merge pull request #53 from lucy2512/main
saritapatel8770 Oct 3, 2022
e4257b8
Merge pull request #52 from vatsal9117/main
saritapatel8770 Oct 3, 2022
e42a503
Longest Substring Without Repeating Characters
Carrajaula Oct 3, 2022
f69d713
Create Linked List Cycle.cpp
GauravGowda Oct 3, 2022
7527632
Create Merge Two Sorted Lists.cpp
GauravGowda Oct 3, 2022
016bcaf
Create Remove Nth Node From End of List.cpp
GauravGowda Oct 3, 2022
7c32fbb
Create Design Linked List.cpp
GauravGowda Oct 3, 2022
b6cc9c2
added solution
RishabhSharma96 Oct 3, 2022
0e3b5f4
Add Remove Palindromic Subsequences in JavaScript
rahulrk-dev Oct 3, 2022
0d956d0
Add solution to Maximum Erasure Value
Cursed-Ninja Oct 3, 2022
479733d
fin
gautamV19 Oct 3, 2022
3cd17c5
Create permutations.cpp
55ritesh Oct 3, 2022
f5ff3e1
First_Missing_Positive.cpp
yashkhandelwal2203 Oct 3, 2022
349907b
120. Triangle solution in 4 approach
kishan0921 Oct 3, 2022
6fbfc22
Longest_valid_parenthesis solution
kishan0921 Oct 3, 2022
630ed24
1695.Maximum_Erasure_Value program solution in c++
kishan779 Oct 3, 2022
a6322c0
longest valid parenthesis
kishan779 Oct 3, 2022
ca81edc
Longest Substring Without Repeating Characters solution in c++
Kishansharma06 Oct 3, 2022
34b1a6e
Create Combination_Sum_II.py
vatsal9117 Oct 4, 2022
6b00209
Create Delete-Operation-for-Two-Strings Delete-Operation-for-Two-Str…
krishnasharma1386 Oct 4, 2022
b835b0f
Create tringle.py
krishnasharma1386 Oct 4, 2022
e26e917
Update Combination_Sum_II.py
vatsal9117 Oct 4, 2022
b07fbf7
Delete Combination_Sum_II.py
vatsal9117 Oct 4, 2022
5c43cad
Merge pull request #87 from krishnasharma1386/main
saritapatel8770 Oct 4, 2022
563a4fd
Merge pull request #86 from vatsal9117/main
saritapatel8770 Oct 4, 2022
617f712
Merge pull request #85 from Kishansharma06/main
saritapatel8770 Oct 4, 2022
bbd10e0
Merge pull request #84 from kishan779/main
saritapatel8770 Oct 4, 2022
a8ab89d
Merge pull request #83 from kishan0921/main
saritapatel8770 Oct 4, 2022
df8a9b1
Merge pull request #82 from yashkhandelwal2203/main
saritapatel8770 Oct 4, 2022
9508e4c
Merge pull request #81 from 55ritesh/main
saritapatel8770 Oct 4, 2022
0a7b4a0
Merge pull request #80 from gautamV19/dev-g
saritapatel8770 Oct 4, 2022
4f99a73
Merge pull request #79 from Cursed-Ninja/main
saritapatel8770 Oct 4, 2022
e2c1d62
Merge pull request #78 from DevTMK/DevTMK/removePalindromicSubsequenc…
saritapatel8770 Oct 4, 2022
1754d14
Merge pull request #77 from RishabhSharma96/main
saritapatel8770 Oct 4, 2022
9907108
Merge pull request #76 from GauravGowda/patch-4
saritapatel8770 Oct 4, 2022
066f692
Merge pull request #75 from GauravGowda/patch-3
saritapatel8770 Oct 4, 2022
c9c0081
Merge pull request #74 from GauravGowda/patch-2
saritapatel8770 Oct 4, 2022
ca5594e
Merge pull request #73 from GauravGowda/patch-1
saritapatel8770 Oct 4, 2022
54da0f6
Merge pull request #72 from lyallemma/main
saritapatel8770 Oct 4, 2022
5f0ba65
1658. Minimum Operations to Reduce X to Zero
krishnasharma1386 Oct 4, 2022
322d2b5
Added cpp solution for Delete Operation for two strings
Oct 4, 2022
f928b1e
Merge pull request #88 from krishnasharma1386/main
saritapatel8770 Oct 4, 2022
2df9c26
Update README.md
saritapatel8770 Oct 4, 2022
46e9a4c
Merge pull request #89 from joelsathi/hacktoberfest
saritapatel8770 Oct 4, 2022
ab03280
fin
gautamV19 Oct 4, 2022
6f505ca
fin
gautamV19 Oct 4, 2022
814eed6
fin
gautamV19 Oct 4, 2022
6a0ec70
triangle fin
gautamV19 Oct 4, 2022
7e552c5
triangle question fin
gautamV19 Oct 4, 2022
86f55e0
longest substring question fin
gautamV19 Oct 4, 2022
af3c94a
lru cache in java
00suryavanshi00 Oct 4, 2022
c120164
Add Insert Interval in JavaScript
rahulrk-dev Oct 4, 2022
2238294
Permutations Python code
DEBADYUTI-KARMAKAR Oct 4, 2022
df228eb
Insert-Interval(JAVA) solution added
raazanand Oct 5, 2022
8de0fd7
Merge pull request #97 from raazanand/main
saritapatel8770 Oct 5, 2022
d28a659
Merge pull request #96 from DEBADYUTI-KARMAKAR/main
saritapatel8770 Oct 5, 2022
db556e7
Merge pull request #95 from DevTMK/DevTMK/insertInterval-js
saritapatel8770 Oct 5, 2022
92a169e
Merge pull request #93 from 00suryavanshi00/solution
saritapatel8770 Oct 5, 2022
f29d646
Merge pull request #92 from gautamV19/dev-gautam-3
saritapatel8770 Oct 5, 2022
83c4a09
Triangle C++ solution
paras3624 Oct 5, 2022
8cc64bc
Merge pull request #98 from paras3624/main
saritapatel8770 Oct 5, 2022
6a4a732
Combination Sum II
DEBADYUTI-KARMAKAR Oct 5, 2022
bd7c3c3
Create Maximum Sliding problem
RiteshJha2000 Oct 5, 2022
237f54b
Add files via upload
HeroKillerStain Oct 5, 2022
b7bd501
Create Insert-Interval.java
Dhanshriborse Oct 6, 2022
62d05bb
Create Minimum_Operations_to_Reduce_X_to_Zero.java
Dhanshriborse Oct 6, 2022
a736c17
Same Tree
DEBADYUTI-KARMAKAR Oct 6, 2022
deba37f
Merge pull request #103 from Dhanshriborse/patch-4
saritapatel8770 Oct 6, 2022
4fcb096
Merge pull request #102 from Dhanshriborse/patch-3
saritapatel8770 Oct 6, 2022
8244468
Merge pull request #101 from HeroKillerStain/main
saritapatel8770 Oct 6, 2022
da0f0c2
Merge pull request #100 from RiteshJha2000/patch-1
saritapatel8770 Oct 6, 2022
d9f3dc1
Merge pull request #99 from DEBADYUTI-KARMAKAR/main
saritapatel8770 Oct 6, 2022
75f5355
Added Solution based on #68
joelsathi Oct 7, 2022
02c06c5
Median of Two Sorted Arrays
DEBADYUTI-KARMAKAR Oct 7, 2022
728b831
Two Sum IV - Input is a BST Solution Added in java language.
Aadityapburujwale Oct 9, 2022
da1aba8
Leetcode 14 Days Study Plan (Day1 Java Solutions Added)
Aadityapburujwale Oct 9, 2022
88e285a
Leetcode 14 Days Study Plan (Day2 to Day5 Java Solutions Added)
Aadityapburujwale Oct 9, 2022
1500307
Create Running Sum of 1d Array
Maheshkanhere Oct 9, 2022
0af675a
Merge pull request #107 from Maheshkanhere/patch-1
saritapatel8770 Oct 10, 2022
80947f5
Merge pull request #106 from Aadityapburujwale/main
saritapatel8770 Oct 10, 2022
abd1684
Merge pull request #105 from DEBADYUTI-KARMAKAR/main
saritapatel8770 Oct 10, 2022
74ab6da
Merge pull request #104 from joelsathi/patch-1
saritapatel8770 Oct 10, 2022
c360770
Merge branch 'main' of https://github.com/Aadityapburujwale/Leetcode-…
Aadityapburujwale Oct 10, 2022
df146fa
Add Insert Interval Solution
SarojWasti Oct 10, 2022
c682e26
added solution in java
00suryavanshi00 Oct 10, 2022
2ed9b5c
Merge pull request #110 from 00suryavanshi00/solution
saritapatel8770 Oct 10, 2022
961a984
Merge pull request #109 from SarojWasti/Insert-interval-sarojwasti
saritapatel8770 Oct 10, 2022
4baca99
Merge pull request #108 from Aadityapburujwale/main
saritapatel8770 Oct 10, 2022
01676e8
trapping rain water
DEBADYUTI-KARMAKAR Oct 10, 2022
2919d41
Added Python code for Longest Valid Parentheses
Bana25 Oct 11, 2022
c38b5fb
Merge pull request #112 from Bana25/main
saritapatel8770 Oct 13, 2022
90b949d
Merge pull request #111 from DEBADYUTI-KARMAKAR/main
saritapatel8770 Oct 13, 2022
9f8a8c8
Create Delete-Operation-for-Two-Strings.java
Aadityapburujwale Oct 14, 2022
4c2f863
Merge pull request #113 from Aadityapburujwale/patch-1
saritapatel8770 Oct 14, 2022
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
89 changes: 89 additions & 0 deletions 120.Triangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@




//1. Recursion


// Recursion *** Will Give TLE ***


int solve(int i, int j, int n, vector<vector<int>>&triangle) {
if(i == n - 1)
return triangle[i][j];
int bottom = triangle[i][j] + solve(i+1, j, n, triangle);
int bottom_right = triangle[i][j] + solve(i+1, j+1, n, triangle);
return min(bottom, bottom_right);
}
int minimumTotal(vector<vector<int>>& triangle) {
int n = triangle.size();
return solve(0, 0, n, triangle);
}


//2. Memoization


// Memoization
int solve(int i, int j, int n, vector<vector<int>>&triangle, vector<vector<int>>&dp) {
if(i == n - 1)
return triangle[i][j];
if(dp[i][j] != -1)
return dp[i][j];
int bottom = triangle[i][j] + solve(i+1, j, n, triangle, dp);
int bottom_right = triangle[i][j] + solve(i+1, j+1, n, triangle, dp);
return dp[i][j] = min(bottom, bottom_right);
}
int minimumTotal(vector<vector<int>>& triangle) {
int n = triangle.size();
vector<vector<int>>dp(n, vector<int>(n, -1));
return solve(0, 0, n, triangle, dp);

}


// 3. Tabulation

// Tabulation
int minimumTotal(vector<vector<int>>& triangle) {
int n = triangle.size();
vector<vector<int>>dp(n, vector<int>(n, -1));
for(int i = 0; i < n; i++)
dp[n-1][i] = triangle[n-1][i];
for(int i = n-2; i >= 0; i--) {
for(int j = i; j >= 0; j--) {
int up = triangle[i][j] + dp[i+1][j];
int up_left = triangle[i][j] + dp[i+1][j+1];
dp[i][j] = min(up, up_left);
}
}
return dp[0][0];
}


//4. Space Optimal

// Space Optimization
int minimumTotal(vector<vector<int>>& triangle) {
int n = triangle.size();
vector<int>next(n);
for(int i = n-1; i >= 0; i--) {
vector<int>curr(n);
for(int j = i; j >= 0; j--) {
if(i == n-1)
curr[j] = triangle[i][j];
else {
int up = triangle[i][j] + next[j];
int up_left = triangle[i][j] + next[j+1];
curr[j] = min(up, up_left);
}
}
next = curr;
}
return next[0];
}





29 changes: 29 additions & 0 deletions 140.-Word-Break-II.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class Solution {
HashMap<Integer, List<String>> dp = new HashMap<>();

public List<String> wordBreak(String s, Set<String> wordDict) {
int maxLength = -1;
for(String ss : wordDict) maxLength = Math.max(maxLength, ss.length());
return addSpaces(s, wordDict, 0, maxLength);
}

private List<String> addSpaces(String s, Set<String> wordDict, int start, int max){
List<String> words = new ArrayList<>();
if(start == s.length()) {
words.add("");
return words;
}
for(int i = start + 1; i <= max + start && i <= s.length(); i++){
String temp = s.substring(start, i);
if(wordDict.contains(temp)){
List<String> ll;
if(dp.containsKey(i)) ll = dp.get(i);
else ll = addSpaces(s, wordDict, i, max);
for(String ss : ll) words.add(temp + (ss.equals("") ? "" : " ") + ss);
}

}
dp.put(start, words);
return words;
}
}
31 changes: 31 additions & 0 deletions 140_Word_Break_II.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Solution {
public:

void f(int i, int j, string s, vector<string>&wordDict, int n, vector<string>&ans, map<string, bool>&m, string &temp) {

if(i>=n && j>=n) {
ans.push_back(temp);
return;
}
if(j>=n) return;
string str = s.substr(i, j-i+1);
if(m.find(str)!=m.end()) {
string st = temp;
temp+=str;
if(j!=n-1) temp+=" ";
f(j+1, j+1, s, wordDict, n, ans, m, temp);
temp = st;
}
f(i, j+1, s, wordDict, n, ans, m, temp);
}

vector<string> wordBreak(string s, vector<string>& wordDict) {
int n = s.size();
map <string, bool> m;
for(int i=0; i<wordDict.size(); i++) m[wordDict[i]]=1;
vector<string> ans;
string temp="";
f(0, 0, s, wordDict, n, ans, m, temp);
return ans;
}
};
69 changes: 69 additions & 0 deletions 146_LRU_Cache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class LRUCache {
public:
class node{
public:
int k;
int v;
node *prev;
node *next;
node(int kk,int vv){
k=kk;
v=vv;
}
};

node* head=new node(-1,-1);
node* tail=new node(-1,-1);


int cap;
unordered_map<int,node*> m;

LRUCache(int capacity) {
cap=capacity;
head->next=tail;
tail->prev=head;
}

void insertNode(node* newNode){
node* temp=head->next;
newNode->next=temp;
newNode->prev=head;
head->next=newNode;
temp->prev=newNode;
}

void deleteNode(node* delNode){
node* delPrev=delNode->prev;
node* delNext=delNode->next;
delPrev->next=delNext;
delNext->prev=delPrev;
}

int get(int key) {
if(m.find(key)!=m.end()){
node* resNode=m[key];
int res=resNode->v;
m.erase(key);
deleteNode(resNode);
insertNode(resNode);
m[key]=head->next;
return res;
}
return -1;
}

void put(int key, int value) {
if(m.find(key)!=m.end()){
node* exitingNode = m[key];
m.erase(key);
deleteNode(exitingNode);
}
if(m.size() == cap){
m.erase(tail->prev->k);
deleteNode(tail-> prev);
}
insertNode(new node(key,value));
m[key]=head->next;
}
};
27 changes: 27 additions & 0 deletions 1695.Maximum_Erasure_Value.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
public:
int maximumUniqueSubarray(vector<int>& nums) {
int curr_sum=0, res=0;

//set to store the elements
unordered_set<int> st;

int i=0,j=0;
while(j<nums.size()) {
while(st.count(nums[j])>0) {
//Removing the ith element untill we reach the repeating element
st.erase(nums[i]);
curr_sum-=nums[i];
i++;
}
//Add the current element to set and curr_sum value
curr_sum+=nums[j];
st.insert(nums[j++]);

//res variable to keep track of largest curr_sum encountered till now...
res = max(res, curr_sum);
}

return res;
}
};
19 changes: 19 additions & 0 deletions 33. Search in Rotated Sorted Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def search(self, nums: List[int], target: int) -> int:
l,r = 0,len(nums)-1
while(l<=r):
mid = (l+r)//2
if target == nums[mid]:
return mid

if nums[l]<=nums[mid]:
if target > nums[mid] or target < nums[l]:
l = mid + 1
else:
r = mid - 1
else:
if target < nums[mid] or target > nums[r]:
r = mid - 1
else:
l = mid + 1
return -1
66 changes: 66 additions & 0 deletions Combination Sum II/combination_sum_II.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Sorts the array in ascending order */
int sortFunc(const void* a, const void* b) {
return *((int*)a) - *((int*)b);
}

void helper(int* candidates, int candidatesSize, int target, int index, int* current, int currentLength, int* returnSize, int** returnColumnSizes, int*** answer) {
/* Track the previous candidate to avoid duplicate solutions*/
int prevCan = 0;

/* Loop through all possible candidates to add to the solution */
for (int i = index; i < candidatesSize; i++) {

/* If the candidate matches the target, add to the answer */
if (candidates[i] == target) {
(*returnSize)++;

/* Allocate memory for new answer */
*answer = (int**)realloc(*answer, (*returnSize) * sizeof(int*));
(*answer)[(*returnSize) - 1] = (int*)malloc((currentLength+1) * sizeof(int));

/* Copy data into new answer */
memcpy((*answer)[(*returnSize) - 1], current, currentLength * sizeof(int));
(*answer)[(*returnSize) - 1][currentLength] = candidates[i];

/* Update the returnColumnSizes array */
(*returnColumnSizes) = (int*)realloc((*returnColumnSizes), (*returnSize) * sizeof(int));
(*returnColumnSizes)[(*returnSize) - 1] = currentLength + 1;

/* Break to avoid duplicate answers */
/* Since the candidates are sorted, any next candidates will be too large */
break;
}

/* If the candidate could possibly work, add it to the current answer and recursively call the helper */
else if (candidates[i] <= (target / 2) && candidates[i] != prevCan) {
current[currentLength] = candidates[i];
helper(candidates, candidatesSize, target - candidates[i], i + 1, current, currentLength + 1, returnSize, returnColumnSizes, answer);
prevCan = candidates[i];
}

/* Since the list is sorted, break once the candidate is too large */
else if (candidates[i] > target) break;
}
}

int** combinationSum2(int* candidates, int candidatesSize, int target, int* returnSize, int** returnColumnSizes){

/* Sort the candidates to group duplicates together */
qsort(candidates, candidatesSize, sizeof(int), sortFunc);

/* Array to store the current solution */
int* current = (int*)malloc(100*sizeof(int));
int currentLength = 0;

/* Allocate initial memory to answer and returnColumnSizes */
int** answer = (int**)malloc(sizeof(int*));
(*returnColumnSizes) = (int*)malloc(sizeof(int));

(*returnSize) = 0;

/* Call the helper with our initial conditions */
helper(candidates, candidatesSize, target, 0, current, currentLength, returnSize, returnColumnSizes, &answer);

free(current);
return answer;
}
Empty file.
33 changes: 33 additions & 0 deletions Delete-Operation-for-Two-Strings/CPP Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<bits/stdc++.h>

using namespace std;

class Solution {
public:
int minDistance(string word1, string word2) {
// Bottom up approach
int m, n;
m = word1.length();
n = word2.length();
int dp[m + 1][n + 1];

for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
// we have to add all the remaining char in word2
if (i == 0)
dp[i][j] = j;
// We have to delete all the remaining characters from word 1
else if (j == 0)
dp[i][j] = i;
// If in the memo dict return the val
else if (word1[i - 1] == word2[j - 1])
dp[i][j] = dp[i - 1][j - 1];

else
dp[i][j] = 1 + min(dp[i][j - 1], dp[i - 1][j]);
}
}

return dp[m][n];
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def minDistance(self, word1: str, word2: str) -> int:
m = len(word1)
n = len(word2)
dp = [0] * (n + 1)

for j in range(n + 1):
dp[j] = j

for i in range(1, m + 1):
newDp = [i] + [0] * n
for j in range(1, n + 1):
if word1[i - 1] == word2[j - 1]:
newDp[j] = dp[j - 1]
else:
newDp[j] = min(newDp[j - 1], dp[j]) + 1
dp = newDp

return dp[n]
Loading