Skip to content

Commit 6bca815

Browse files
authored
Merge pull request #1185 from SadafKausar2025/solution
Added leetcode 209 - Minimum size subarray sum (Medium)
2 parents 4e13b30 + 48a6b45 commit 6bca815

File tree

4 files changed

+294
-79
lines changed

4 files changed

+294
-79
lines changed

dsa-problems/leetcode-problems/0200-0299.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const problems = [
6868
"problemName": "209. Minimum Size Subarray Sum",
6969
"difficulty": "Medium",
7070
"leetCodeLink": "https://leetcode.com/problems/minimum-size-subarray-sum",
71-
"solutionLink": "#"
71+
"solutionLink": "/dsa-solutions/lc-solutions/0200-0299/minimum-size-subarray-sum"
7272
},
7373
{
7474
"problemName": "210. Course Schedule II",

dsa-solutions/lc-solutions/0000-0099/0017-Letter-Combinations-of-a-Phone-Number.md

Lines changed: 65 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ id: letter-combinations-of-a-phone-number
33
title: Letter Combinations of a Phone Number (LeetCode)
44
sidebar_label: 0017 Letter Combinations of a Phone Number
55
tags:
6-
- Back Tracking
7-
- Mapping
8-
- String
6+
- Back Tracking
7+
- Mapping
8+
- String
99
description: The problem requires generating all letter combinations corresponding to given digits (2-9). The solution utilizes backtracking to explore all combinations efficiently, employing a recursive approach in Java.
10-
sidebar_position: 17
1110
---
1211

1312
## Problem Description
1413

15-
| Problem Statement | Solution Link | LeetCode Profile |
16-
| :------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------- |
17-
| [Letter Combinations of a Phone Number](https://leetcode.com/problems/Letter Combinations of a Phone Number/) | [Letter Combinations of a Phone Number Solution on LeetCode](https://leetcode.com/problems/Letter Combinations of a Phone Number/solutions/5055810/video-two-pointer-solution/) | [gabaniyash846](https://leetcode.com/u/gabaniyash846/) |
14+
| Problem Statement | Solution Link | LeetCode Profile |
15+
| :----------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------- |
16+
| [Letter Combinations of a Phone Number](https://leetcode.com/problems/Letter Combinations of a Phone Number/) | [Letter Combinations of a Phone Number Solution on LeetCode](https://leetcode.com/problems/Letter Combinations of a Phone Number/solutions/5055810/video-two-pointer-solution/) | [gabaniyash846](https://leetcode.com/u/gabaniyash846/) |
1817

1918
### Problem Description
2019

2120
## Problem Statement:
22-
2321
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.
2422

2523
### Examples
@@ -34,6 +32,7 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
3432
- **Input:** `digits = ""`
3533
- **Output:** `[]`
3634

35+
3736
#### Example 3
3837

3938
- **Input:** `2`
@@ -48,11 +47,9 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
4847
### Approach
4948

5049
1. **Mapping Digits to Letters:**
51-
5250
- Define a mapping of digits to their corresponding letters, similar to telephone buttons.
5351

5452
2. **Backtracking Function:**
55-
5653
- Define a recursive backtracking function to generate all possible combinations.
5754
- The function takes four parameters:
5855
- `index`: The current index in the digits string.
@@ -62,7 +59,6 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
6259
- After the recursive call, we remove the last character from the combination (backtracking).
6360

6461
3. **Base Case:**
65-
6662
- If the length of the current combination is equal to the length of the input digits string, we add the combination to the result list.
6763

6864
4. **Main Function:**
@@ -157,7 +153,6 @@ public class Solution {
157153
```
158154

159155
#### CPP:
160-
161156
```cpp
162157
#include <iostream>
163158
#include <vector>
@@ -213,82 +208,80 @@ int main() {
213208
```
214209
215210
#### JavaScript
216-
217211
```js
218212
/**
219213
* @param {string} digits
220214
* @return {string[]}
221215
*/
222-
var letterCombinations = function (digits) {
223-
if (digits.length === 0) return [];
224-
225-
const digitToLetters = {
226-
2: "abc",
227-
3: "def",
228-
4: "ghi",
229-
5: "jkl",
230-
6: "mno",
231-
7: "pqrs",
232-
8: "tuv",
233-
9: "wxyz",
234-
};
235-
236-
const combinations = [];
237-
238-
const backtrack = (index, path) => {
239-
if (index === digits.length) {
240-
combinations.push(path);
241-
return;
242-
}
243-
const letters = digitToLetters[digits.charAt(index)];
244-
for (let letter of letters) {
245-
backtrack(index + 1, path + letter);
246-
}
247-
};
248-
249-
backtrack(0, "");
250-
return combinations;
216+
var letterCombinations = function(digits) {
217+
if (digits.length === 0) return [];
218+
219+
const digitToLetters = {
220+
'2': 'abc',
221+
'3': 'def',
222+
'4': 'ghi',
223+
'5': 'jkl',
224+
'6': 'mno',
225+
'7': 'pqrs',
226+
'8': 'tuv',
227+
'9': 'wxyz'
228+
};
229+
230+
const combinations = [];
231+
232+
const backtrack = (index, path) => {
233+
if (index === digits.length) {
234+
combinations.push(path);
235+
return;
236+
}
237+
const letters = digitToLetters[digits.charAt(index)];
238+
for (let letter of letters) {
239+
backtrack(index + 1, path + letter);
240+
}
241+
};
242+
243+
backtrack(0, '');
244+
return combinations;
251245
};
252246
253247
// Example usage:
254248
console.log(letterCombinations("23")); // Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
255249
```
256250

257251
#### TypeScript
258-
259252
```ts
260253
class Solution {
261-
private digitToLetters: { [key: string]: string } = {
262-
"2": "abc",
263-
"3": "def",
264-
"4": "ghi",
265-
"5": "jkl",
266-
"6": "mno",
267-
"7": "pqrs",
268-
"8": "tuv",
269-
"9": "wxyz",
270-
};
271-
272-
letterCombinations(digits: string): string[] {
273-
const combinations: string[] = [];
274-
275-
const backtrack = (index: number, path: string): void => {
276-
if (index === digits.length) {
277-
combinations.push(path);
278-
return;
279-
}
280-
const letters = this.digitToLetters[digits.charAt(index)];
281-
for (let letter of letters) {
282-
backtrack(index + 1, path + letter);
283-
}
254+
private digitToLetters: { [key: string]: string } = {
255+
'2': 'abc',
256+
'3': 'def',
257+
'4': 'ghi',
258+
'5': 'jkl',
259+
'6': 'mno',
260+
'7': 'pqrs',
261+
'8': 'tuv',
262+
'9': 'wxyz'
284263
};
285264

286-
if (digits.length !== 0) {
287-
backtrack(0, "");
288-
}
265+
letterCombinations(digits: string): string[] {
266+
const combinations: string[] = [];
267+
268+
const backtrack = (index: number, path: string): void => {
269+
if (index === digits.length) {
270+
combinations.push(path);
271+
return;
272+
}
273+
const letters = this.digitToLetters[digits.charAt(index)];
274+
for (let letter of letters) {
275+
backtrack(index + 1, path + letter);
276+
}
277+
};
289278

290-
return combinations;
291-
}
279+
if (digits.length !== 0) {
280+
backtrack(0, '');
281+
}
282+
283+
return combinations;
284+
}
292285
}
293286

294287
// Example usage:
@@ -301,11 +294,9 @@ console.log(solution.letterCombinations("23")); // Output: ["ad","ae","af","bd",
301294
Here's a step-by-step algorithm for generating all possible letter combinations of a given string of digits using backtracking:
302295

303296
1. **Define a mapping of digits to letters:**
304-
305297
- Create a map where each digit from 2 to 9 is mapped to its corresponding letters on a telephone keypad.
306298

307299
2. **Define a backtracking function:**
308-
309300
- The function will take the following parameters:
310301
- `index`: The current index in the digits string.
311302
- `path`: The current combination of letters.
@@ -314,12 +305,11 @@ Here's a step-by-step algorithm for generating all possible letter combinations
314305
- After the recursive call, remove the last character from the combination (backtracking).
315306

316307
3. **Base Case:**
317-
318308
- If the length of the current combination is equal to the length of the input digits string, add the combination to the result list.
319309

320310
4. **Main Function:**
321311
- Initialize an empty list to store the combinations.
322312
- Call the backtracking function with the initial index set to 0 and an empty string as the initial combination.
323313
- Return the list of combinations.
324314

325-
This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.
315+
This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.

dsa-solutions/lc-solutions/0200-0299/0206-Reverse-Linkedlist.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ tags:
1111
description: "This document provides solutions for determining the Reverse Linkedlist."
1212
---
1313

14-
# 0206-Reverse LinkedList
15-
16-
### Problem Statement
14+
## Problem Statement
1715

1816
Given the head of a singly linked list, reverse the list, and return the reversed list.
1917

0 commit comments

Comments
 (0)