Skip to content

Commit ab0d26a

Browse files
authored
Added tasks 3280-3292
1 parent b783a8c commit ab0d26a

File tree

13 files changed

+1106
-7
lines changed
  • src/main/java/g3201_3300
    • s3280_convert_date_to_binary
    • s3281_maximize_score_of_numbers_in_ranges
    • s3282_reach_end_of_array_with_max_score
    • s3283_maximum_number_of_moves_to_kill_all_pawns
    • s3285_find_indices_of_stable_mountains
    • s3286_find_a_safe_walk_through_a_grid
    • s3287_find_the_maximum_sequence_value_of_array
    • s3288_length_of_the_longest_increasing_path
    • s3289_the_two_sneaky_numbers_of_digitville
    • s3290_maximum_multiplication_score
    • s3291_minimum_number_of_valid_strings_to_form_target_i
    • s3292_minimum_number_of_valid_strings_to_form_target_ii

13 files changed

+1106
-7
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
|-|-|-|-|-|-
6161
| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 100.00
6262
| 0283 |[Move Zeroes](src/main/java/g0201_0300/s0283_move_zeroes)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 79.54
63-
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 2 | 85.97
63+
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 85.97
6464
| 0217 |[Contains Duplicate](src/main/java/g0201_0300/s0217_contains_duplicate)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 6 | 96.68
6565
| 0058 |[Length of Last Word](src/main/java/g0001_0100/s0058_length_of_last_word)| Easy | String | 0 | 100.00
6666
| 0605 |[Can Place Flowers](src/main/java/g0601_0700/s0605_can_place_flowers)| Easy | Array, Greedy | 1 | 96.77
@@ -244,7 +244,7 @@
244244

245245
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
246246
|-|-|-|-|-|-
247-
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 2 | 85.97
247+
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 85.97
248248
| 0088 |[Merge Sorted Array](src/main/java/g0001_0100/s0088_merge_sorted_array)| Easy | Top_Interview_Questions, Array, Sorting, Two_Pointers | 0 | 100.00
249249

250250
#### Day 3 Array
@@ -409,7 +409,7 @@
409409

410410
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
411411
|-|-|-|-|-|-
412-
| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 1 | 100.00
412+
| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 100.00
413413
| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
414414

415415
#### Day 11 Linked List
@@ -1330,7 +1330,7 @@
13301330

13311331
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
13321332
|-|-|-|-|-|-
1333-
| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 1 | 100.00
1333+
| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 100.00
13341334
| 0445 |[Add Two Numbers II](src/main/java/g0401_0500/s0445_add_two_numbers_ii)| Medium | Math, Stack, Linked_List | 3 | 90.38
13351335

13361336
#### Day 16
@@ -1648,7 +1648,7 @@
16481648

16491649
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
16501650
|-|-|-|-|-|-
1651-
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 2 | 85.97
1651+
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 85.97
16521652
| 0299 |[Bulls and Cows](src/main/java/g0201_0300/s0299_bulls_and_cows)| Medium | String, Hash_Table, Counting | 6 | 86.69
16531653

16541654
#### Day 14 Stack
@@ -1816,6 +1816,18 @@
18161816

18171817
| # | Title | Difficulty | Tag | Time, ms | Time, %
18181818
|------|----------------|-------------|-------------|----------|--------
1819+
| 3292 |[Minimum Number of Valid Strings to Form Target II](src/main/java/g3201_3300/s3292_minimum_number_of_valid_strings_to_form_target_ii)| Hard | Array, String, Dynamic_Programming, Binary_Search, Segment_Tree, Hash_Function, String_Matching, Rolling_Hash | 103 | 100.00
1820+
| 3291 |[Minimum Number of Valid Strings to Form Target I](src/main/java/g3201_3300/s3291_minimum_number_of_valid_strings_to_form_target_i)| Medium | Array, String, Dynamic_Programming, Binary_Search, Trie, Segment_Tree, Hash_Function, String_Matching, Rolling_Hash | 263 | 60.00
1821+
| 3290 |[Maximum Multiplication Score](src/main/java/g3201_3300/s3290_maximum_multiplication_score)| Medium | Array, Dynamic_Programming | 8 | 100.00
1822+
| 3289 |[The Two Sneaky Numbers of Digitville](src/main/java/g3201_3300/s3289_the_two_sneaky_numbers_of_digitville)| Easy | Array, Hash_Table, Math | 3 | 100.00
1823+
| 3288 |[Length of the Longest Increasing Path](src/main/java/g3201_3300/s3288_length_of_the_longest_increasing_path)| Hard | Array, Sorting, Binary_Search | 34 | 100.00
1824+
| 3287 |[Find the Maximum Sequence Value of Array](src/main/java/g3201_3300/s3287_find_the_maximum_sequence_value_of_array)| Hard | Array, Dynamic_Programming, Bit_Manipulation | 1140 | 100.00
1825+
| 3286 |[Find a Safe Walk Through a Grid](src/main/java/g3201_3300/s3286_find_a_safe_walk_through_a_grid)| Medium | Array, Matrix, Heap_Priority_Queue, Graph, Shortest_Path, Breadth_First_Search | 90 | 100.00
1826+
| 3285 |[Find Indices of Stable Mountains](src/main/java/g3201_3300/s3285_find_indices_of_stable_mountains)| Easy | Array | 1 | 100.00
1827+
| 3283 |[Maximum Number of Moves to Kill All Pawns](src/main/java/g3201_3300/s3283_maximum_number_of_moves_to_kill_all_pawns)| Hard | Array, Math, Breadth_First_Search, Bit_Manipulation, Bitmask, Game_Theory | 250 | 98.43
1828+
| 3282 |[Reach End of Array With Max Score](src/main/java/g3201_3300/s3282_reach_end_of_array_with_max_score)| Medium | Array, Greedy | 9 | 100.00
1829+
| 3281 |[Maximize Score of Numbers in Ranges](src/main/java/g3201_3300/s3281_maximize_score_of_numbers_in_ranges)| Medium | Array, Sorting, Greedy, Binary_Search | 47 | 100.00
1830+
| 3280 |[Convert Date to Binary](src/main/java/g3201_3300/s3280_convert_date_to_binary)| Easy | String, Math | 3 | 100.00
18191831
| 3277 |[Maximum XOR Score Subarray Queries](src/main/java/g3201_3300/s3277_maximum_xor_score_subarray_queries)| Hard | Array, Dynamic_Programming | 29 | 98.87
18201832
| 3276 |[Select Cells in Grid With Maximum Score](src/main/java/g3201_3300/s3276_select_cells_in_grid_with_maximum_score)| Hard | Array, Dynamic_Programming, Matrix, Bit_Manipulation, Bitmask | 6 | 99.82
18211833
| 3275 |[K-th Nearest Obstacle Queries](src/main/java/g3201_3300/s3275_k_th_nearest_obstacle_queries)| Medium | Array, Heap_Priority_Queue | 33 | 100.00
@@ -4421,6 +4433,6 @@
44214433
| 0005 |[Longest Palindromic Substring](src/main/java/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Data_Structure_II_Day_9_String, Algorithm_II_Day_14_Dynamic_Programming, Dynamic_Programming_I_Day_17, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 7 | 96.96
44224434
| 0004 |[Median of Two Sorted Arrays](src/main/java/g0001_0100/s0004_median_of_two_sorted_arrays)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1) | 1 | 100.00
44234435
| 0003 |[Longest Substring Without Repeating Characters](src/main/java/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Algorithm_I_Day_6_Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Udemy_Strings, Big_O_Time_O(n)_Space_O(1) | 2 | 99.52
4424-
| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 1 | 100.00
4425-
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Data_Structure_I_Day_2_Array, Level_1_Day_13_Hashmap, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 2 | 85.97
4436+
| 0002 |[Add Two Numbers](src/main/java/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 1 | 100.00
4437+
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Data_Structure_I_Day_2_Array, Level_1_Day_13_Hashmap, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 85.97
44264438

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Java?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Java)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Java?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Java/fork)
3+
4+
## 3280\. Convert Date to Binary
5+
6+
Easy
7+
8+
You are given a string `date` representing a Gregorian calendar date in the `yyyy-mm-dd` format.
9+
10+
`date` can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in `year-month-day` format.
11+
12+
Return the **binary** representation of `date`.
13+
14+
**Example 1:**
15+
16+
**Input:** date = "2080-02-29"
17+
18+
**Output:** "100000100000-10-11101"
19+
20+
**Explanation:**
21+
22+
100000100000, 10, and 11101 are the binary representations of 2080, 02, and 29 respectively.
23+
24+
**Example 2:**
25+
26+
**Input:** date = "1900-01-01"
27+
28+
**Output:** "11101101100-1-1"
29+
30+
**Explanation:**
31+
32+
11101101100, 1, and 1 are the binary representations of 1900, 1, and 1 respectively.
33+
34+
**Constraints:**
35+
36+
* `date.length == 10`
37+
* `date[4] == date[7] == '-'`, and all other `date[i]`'s are digits.
38+
* The input is generated such that `date` represents a valid Gregorian calendar date between Jan 1<sup>st</sup>, 1900 and Dec 31<sup>st</sup>, 2100 (both inclusive).
39+
40+
## Solution
41+
42+
```java
43+
public class Solution {
44+
private String helper(String str) {
45+
return Integer.toBinaryString(Integer.parseInt(str));
46+
}
47+
48+
public String convertDateToBinary(String date) {
49+
StringBuilder sb = new StringBuilder();
50+
for (String str : date.split("-")) {
51+
sb.append(helper(str));
52+
sb.append("-");
53+
}
54+
sb.deleteCharAt(sb.length() - 1);
55+
return sb.toString();
56+
}
57+
}
58+
```
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Java?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Java)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Java?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Java/fork)
3+
4+
## 3281\. Maximize Score of Numbers in Ranges
5+
6+
Medium
7+
8+
You are given an array of integers `start` and an integer `d`, representing `n` intervals `[start[i], start[i] + d]`.
9+
10+
You are asked to choose `n` integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interval. The **score** of the chosen integers is defined as the **minimum** absolute difference between any two integers that have been chosen.
11+
12+
Return the **maximum** _possible score_ of the chosen integers.
13+
14+
**Example 1:**
15+
16+
**Input:** start = [6,0,3], d = 2
17+
18+
**Output:** 4
19+
20+
**Explanation:**
21+
22+
The maximum possible score can be obtained by choosing integers: 8, 0, and 4. The score of these chosen integers is `min(|8 - 0|, |8 - 4|, |0 - 4|)` which equals 4.
23+
24+
**Example 2:**
25+
26+
**Input:** start = [2,6,13,13], d = 5
27+
28+
**Output:** 5
29+
30+
**Explanation:**
31+
32+
The maximum possible score can be obtained by choosing integers: 2, 7, 13, and 18. The score of these chosen integers is `min(|2 - 7|, |2 - 13|, |2 - 18|, |7 - 13|, |7 - 18|, |13 - 18|)` which equals 5.
33+
34+
**Constraints:**
35+
36+
* <code>2 <= start.length <= 10<sup>5</sup></code>
37+
* <code>0 <= start[i] <= 10<sup>9</sup></code>
38+
* <code>0 <= d <= 10<sup>9</sup></code>
39+
40+
## Solution
41+
42+
```java
43+
import java.util.Arrays;
44+
45+
public class Solution {
46+
public int maxPossibleScore(int[] start, int d) {
47+
Arrays.sort(start);
48+
int n = start.length;
49+
int l = 0;
50+
int r = start[n - 1] - start[0] + d + 1;
51+
while (l < r) {
52+
int m = l + (r - l) / 2;
53+
if (isPossible(start, d, m)) {
54+
l = m + 1;
55+
} else {
56+
r = m;
57+
}
58+
}
59+
return l - 1;
60+
}
61+
62+
private boolean isPossible(int[] start, int d, int score) {
63+
int pre = start[0];
64+
for (int i = 1; i < start.length; i++) {
65+
if (start[i] + d - pre < score) {
66+
return false;
67+
}
68+
pre = Math.max(start[i], pre + score);
69+
}
70+
return true;
71+
}
72+
}
73+
```
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Java?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Java)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Java?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Java/fork)
3+
4+
## 3282\. Reach End of Array With Max Score
5+
6+
Medium
7+
8+
You are given an integer array `nums` of length `n`.
9+
10+
Your goal is to start at index `0` and reach index `n - 1`. You can only jump to indices **greater** than your current index.
11+
12+
The score for a jump from index `i` to index `j` is calculated as `(j - i) * nums[i]`.
13+
14+
Return the **maximum** possible **total score** by the time you reach the last index.
15+
16+
**Example 1:**
17+
18+
**Input:** nums = [1,3,1,5]
19+
20+
**Output:** 7
21+
22+
**Explanation:**
23+
24+
First, jump to index 1 and then jump to the last index. The final score is `1 * 1 + 2 * 3 = 7`.
25+
26+
**Example 2:**
27+
28+
**Input:** nums = [4,3,1,3,2]
29+
30+
**Output:** 16
31+
32+
**Explanation:**
33+
34+
Jump directly to the last index. The final score is `4 * 4 = 16`.
35+
36+
**Constraints:**
37+
38+
* <code>1 <= nums.length <= 10<sup>5</sup></code>
39+
* <code>1 <= nums[i] <= 10<sup>5</sup></code>
40+
41+
## Solution
42+
43+
```java
44+
import java.util.List;
45+
46+
public class Solution {
47+
public long findMaximumScore(List<Integer> nums) {
48+
long res = 0;
49+
long ma = 0;
50+
for (int num : nums) {
51+
res += ma;
52+
ma = Math.max(ma, num);
53+
}
54+
return res;
55+
}
56+
}
57+
```

0 commit comments

Comments
 (0)