Skip to content

Commit 4e5534b

Browse files
committed
Added minor changes
2 parents d4329ff + d0661bb commit 4e5534b

10 files changed

+195
-232
lines changed

Diff for: .gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "algoexpert.io"]
22
path = algoexpert.io
33
url = https://github.com/SunilGudivada/algoexpert.io
4+
[submodule "low-level-design"]
5+
path = low-level-design
6+
url = https://github.com/SunilGudivada/low-level-design

Diff for: geeksForGeeks/POTD/_2022/JAN/_02JAN2022_KSmallestFactor.java

-56
This file was deleted.

Diff for: geeksForGeeks/POTD/_2022/JAN/_03JAN2022_RotateBy90Anticlock.java

-74
This file was deleted.
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package leetCode.Contest.weekly._274;
2+
3+
/**
4+
*
5+
* @docs https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/
6+
* Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.
7+
*
8+
*
9+
*
10+
* Example 1:
11+
*
12+
* Input: s = "aaabbb"
13+
* Output: true
14+
* Explanation:
15+
* The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5.
16+
* Hence, every 'a' appears before every 'b' and we return true.
17+
* Example 2:
18+
*
19+
* Input: s = "abab"
20+
* Output: false
21+
* Explanation:
22+
* There is an 'a' at index 2 and a 'b' at index 1.
23+
* Hence, not every 'a' appears before every 'b' and we return false.
24+
* Example 3:
25+
*
26+
* Input: s = "bbb"
27+
* Output: true
28+
* Explanation:
29+
* There are no 'a's, hence, every 'a' appears before every 'b' and we return true.
30+
*
31+
*
32+
* Constraints:
33+
*
34+
* 1 <= s.length <= 100
35+
* s[i] is either 'a' or 'b'.
36+
*/
37+
public class CheckAappearsBeforeAllB {
38+
public boolean checkString(String s) {
39+
if (s.length() == 1) return true;
40+
int a = s.indexOf("a");
41+
int b = s.indexOf("b");
42+
if (a == -1 || b == -1) {
43+
return true;
44+
}
45+
return s.lastIndexOf("a") < s.indexOf("b");
46+
47+
}
48+
}
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package leetCode.Contest.weekly._274;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the ith asteroid.
7+
*
8+
* You can arrange for the planet to collide with the asteroids in any arbitrary order. If the mass of the planet is greater than or equal to the mass of the asteroid, the asteroid is destroyed and the planet gains the mass of the asteroid. Otherwise, the planet is destroyed.
9+
*
10+
* Return true if all asteroids can be destroyed. Otherwise, return false.
11+
*
12+
*
13+
*
14+
* Example 1:
15+
*
16+
* Input: mass = 10, asteroids = [3,9,19,5,21]
17+
* Output: true
18+
* Explanation: One way to order the asteroids is [9,19,5,3,21]:
19+
* - The planet collides with the asteroid with a mass of 9. New planet mass: 10 + 9 = 19
20+
* - The planet collides with the asteroid with a mass of 19. New planet mass: 19 + 19 = 38
21+
* - The planet collides with the asteroid with a mass of 5. New planet mass: 38 + 5 = 43
22+
* - The planet collides with the asteroid with a mass of 3. New planet mass: 43 + 3 = 46
23+
* - The planet collides with the asteroid with a mass of 21. New planet mass: 46 + 21 = 67
24+
* All asteroids are destroyed.
25+
* Example 2:
26+
*
27+
* Input: mass = 5, asteroids = [4,9,23,4]
28+
* Output: false
29+
* Explanation:
30+
* The planet cannot ever gain enough mass to destroy the asteroid with a mass of 23.
31+
* After the planet destroys the other asteroids, it will have a mass of 5 + 4 + 9 + 4 = 22.
32+
* This is less than 23, so a collision would not destroy the last asteroid.
33+
*
34+
*
35+
* Constraints:
36+
*
37+
* 1 <= mass <= 10^5
38+
* 1 <= asteroids.length <= 10^5
39+
* 1 <= asteroids[i] <= 10^
40+
*/
41+
public class DestroyingAsteriods {
42+
public boolean asteroidsDestroyed(long mass, int[] asteroids) {
43+
Arrays.sort(asteroids);
44+
for (int asteroid : asteroids) {
45+
if ((mass += asteroid) < 2L * asteroid) {
46+
return false;
47+
}
48+
}
49+
return true;
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package leetCode.Contest.weekly._274;
2+
3+
/**
4+
*
5+
* @docs https://leetcode.com/problems/number-of-laser-beams-in-a-bank/
6+
* Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the ith row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device.
7+
* <p>
8+
* There is one laser beam between any two security devices if both conditions are met:
9+
* <p>
10+
* The two devices are located on two different rows: r1 and r2, where r1 < r2.
11+
* For each row i where r1 < i < r2, there are no security devices in the ith row.
12+
* Laser beams are independent, i.e., one beam does not interfere nor join with another.
13+
* <p>
14+
* Return the total number of laser beams in the bank.
15+
* <p>
16+
* <p>
17+
* <p>
18+
* Example 1:
19+
* <p>
20+
* <p>
21+
* Input: bank = ["011001","000000","010100","001000"]
22+
* Output: 8
23+
* Explanation: Between each of the following device pairs, there is one beam. In total, there are 8 beams:
24+
* * bank[0][1] -- bank[2][1]
25+
* * bank[0][1] -- bank[2][3]
26+
* * bank[0][2] -- bank[2][1]
27+
* * bank[0][2] -- bank[2][3]
28+
* * bank[0][5] -- bank[2][1]
29+
* * bank[0][5] -- bank[2][3]
30+
* * bank[2][1] -- bank[3][2]
31+
* * bank[2][3] -- bank[3][2]
32+
* Note that there is no beam between any device on the 0th row with any on the 3rd row.
33+
* This is because the 2nd row contains security devices, which breaks the second condition.
34+
* Example 2:
35+
* <p>
36+
* <p>
37+
* Input: bank = ["000","111","000"]
38+
* Output: 0
39+
* Explanation: There does not exist two devices located on two different rows.
40+
* <p>
41+
* <p>
42+
* Constraints:
43+
* <p>
44+
* m == bank.length
45+
* n == bank[i].length
46+
* 1 <= m, n <= 500
47+
* bank[i][j] is either '0' or '1'.
48+
*/
49+
public class NumberOfLaserBeamsInaBank {
50+
public int numberOfBeams(String[] bank) {
51+
int counter = 0;
52+
int prevcounter = 0;
53+
54+
for (String s : bank) {
55+
int cnt = countBits(s);
56+
if (cnt == 0) continue;
57+
counter += cnt * prevcounter;
58+
59+
prevcounter = cnt;
60+
61+
}
62+
63+
return counter;
64+
}
65+
66+
private int countBits(String s) {
67+
int counter = 0;
68+
for (int i = 0; i < s.length(); i++) {
69+
if (s.charAt(i) == '1') {
70+
counter++;
71+
}
72+
}
73+
74+
return counter;
75+
}
76+
}

Diff for: leetCode/Contest/weekly/_274/Readme.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Leetcode Weekly contest - 274
2+
3+
https://leetcode.com/contest/weekly-contest-274/
4+
5+
- ✳️ - Easy
6+
- ✴️ - Medium
7+
- 🛑 - Hard
8+
9+
Links to the individual problems are included below:
10+
11+
|#|Question Title|Problem Link|
12+
|---|---|---|
13+
||✳️ Check if All A's Appears Before All B's|[Link](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) |
14+
||✴️ Number of Laser Beams in a Bank|[Link](https://leetcode.com/problems/number-of-laser-beams-in-a-bank) |
15+
||✴️ Destroying Asteroids|[Link](https://leetcode.com/problems/destroying-asteroids) |
16+
|🚫|🛑 Maximum Employees to Be Invited to a Meeting|[Link](https://leetcode.com/problems/maximum-employees-to-be-invited-to-a-meeting) |

Diff for: leetCode/DailyChallenge/_2022/JAN/_02JAN2022_PairsofSongsWithTotalDurationsDivisibleby60.java

-42
This file was deleted.

0 commit comments

Comments
 (0)