Skip to content

Commit 18faeee

Browse files
committed
Add 2 problems
1 parent 74dbd38 commit 18faeee

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![DSA Learning](https://img.shields.io/badge/DSA-Learning-blue?style=for-the-badge&logo=leetcode)
44

5-
This repository contains solutions for 588 DSA problems from the [LeetCode](https://leetcode.com/)
5+
This repository contains solutions for 590 DSA problems from the [LeetCode](https://leetcode.com/)
66
website.
77

88
Problems are separated into 20 topics:
@@ -22,12 +22,12 @@ Problems are separated into 20 topics:
2222
| 11 | Interval | [interval](src/interval) | 12 |
2323
| 12 | Linked List | [linked_list](src/linked_list) | 34 |
2424
| 13 | Math | [math](src/math) | 23 |
25-
| 14 | Matrix | [matrix](src/matrix) | 19 |
25+
| 14 | Matrix | [matrix](src/matrix) | 20 |
2626
| 15 | Quad Tree | [quad_tree](src/quad_tree) | 1 |
2727
| 16 | Recursion | [recursion](src/recursion) | 24 |
2828
| 17 | SQL | [sql](src/sql) | 28 |
2929
| 18 | Stack | [stack](src/stack) | 25 |
30-
| 19 | String | [string](src/string) | 61 |
30+
| 19 | String | [string](src/string) | 62 |
3131
| 20 | Trie | [trie](src/trie) | 4 |
3232

3333
## Good places to start your own LeetCode journey
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package matrix;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
/**
7+
* Description: https://leetcode.com/problems/find-smallest-common-element-in-all-rows
8+
* Difficulty: Medium
9+
* Time complexity: O(n * m)
10+
* Space complexity: O(n * m)
11+
*/
12+
public class FindSmallestCommonElementInAllRows {
13+
14+
public int smallestCommonElement(int[][] matrix) {
15+
Map<Integer, Integer> freqMap = new HashMap<>();
16+
for (int i = 0; i < matrix.length; i++) {
17+
for (int j = 0; j < matrix[0].length; j++) {
18+
int count = freqMap.merge(matrix[i][j], 1, Integer::sum);
19+
if (count == matrix.length) return matrix[i][j];
20+
}
21+
}
22+
23+
return -1;
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package string;
2+
3+
/**
4+
* Description: https://leetcode.com/problems/perform-string-shifts
5+
* Difficulty: Easy
6+
* Time complexity: O(n)
7+
* Space complexity: O(n)
8+
*/
9+
public class PerformStringShifts {
10+
11+
public String stringShift(String s, int[][] shifts) {
12+
int netShift = 0;
13+
for (int[] shift : shifts) {
14+
int direction = shift[0] == 0 ? -1 : 1;
15+
netShift += direction * shift[1];
16+
}
17+
18+
netShift %= s.length();
19+
if (netShift == 0) return s;
20+
21+
return netShift < 0
22+
? s.substring(-netShift) + s.substring(0, -netShift) // move left
23+
: s.substring(s.length() - netShift) + s.substring(0, s.length() - netShift); // move right
24+
}
25+
}

0 commit comments

Comments
 (0)