Skip to content

Commit 6b1ee62

Browse files
authored
Added tasks 3232-3235
1 parent b6c0c70 commit 6b1ee62

File tree

13 files changed

+605
-108
lines changed

13 files changed

+605
-108
lines changed

README.md

+108-108
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ implementation 'com.github.javadev:leetcode-in-java:1.34'
3434
> ["For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."](https://www.quora.com/How-effective-is-Leetcode-for-preparing-for-technical-interviews)
3535
3636
##
37-
* [Level 1](#level-1)
3837
* [Level 2](#level-2)
3938
* [Udemy](#udemy)
4039
* [Data Structure I](#data-structure-i)
@@ -48,113 +47,7 @@ implementation 'com.github.javadev:leetcode-in-java:1.34'
4847
* [Programming Skills II](#programming-skills-ii)
4948
* [Graph Theory I](#graph-theory-i)
5049
* [SQL I](#sql-i)
51-
52-
### Level 1
53-
54-
#### Day 1 Prefix Sum
55-
56-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
57-
|-|-|-|-|-|-
58-
| 1480 |[Running Sum of 1d Array](src/main/java/g1401_1500/s1480_running_sum_of_1d_array/Solution.java)| Easy | Array, Prefix_Sum | 0 | 100.00
59-
| 0724 |[Find Pivot Index](src/main/java/g0701_0800/s0724_find_pivot_index/Solution.java)| Easy | Array, Prefix_Sum | 2 | 69.67
60-
61-
#### Day 2 String
62-
63-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
64-
|-|-|-|-|-|-
65-
| 0205 |[Isomorphic Strings](src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java)| Easy | String, Hash_Table | 2 | 99.97
66-
| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers | 1 | 93.01
67-
68-
#### Day 3 Linked List
69-
70-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
71-
|-|-|-|-|-|-
72-
| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
73-
| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
74-
75-
#### Day 4 Linked List
76-
77-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
78-
|-|-|-|-|-|-
79-
| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
80-
| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
81-
82-
#### Day 5 Greedy
83-
84-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
85-
|-|-|-|-|-|-
86-
| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 100.00
87-
| 0409 |[Longest Palindrome](src/main/java/g0401_0500/s0409_longest_palindrome/Solution.java)| Easy | String, Hash_Table, Greedy | 2 | 92.90
88-
89-
#### Day 6 Tree
90-
91-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
92-
|-|-|-|-|-|-
93-
| 0589 |[N-ary Tree Preorder Traversal](src/main/java/g0501_0600/s0589_n_ary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Stack | 1 | 90.98
94-
| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.09
95-
96-
#### Day 7 Binary Search
97-
98-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
99-
|-|-|-|-|-|-
100-
| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Top_100_Liked_Questions, Array, Binary_Search | 0 | 100.00
101-
| 0278 |[First Bad Version](src/main/java/g0201_0300/s0278_first_bad_version/Solution.java)| Easy | Binary_Search, Interactive | 15 | 87.89
102-
103-
#### Day 8 Binary Search Tree
104-
105-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
106-
|-|-|-|-|-|-
107-
| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
108-
| 0235 |[Lowest Common Ancestor of a Binary Search Tree](src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java)| Medium | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 4 | 100.00
109-
110-
#### Day 9 Graph/BFS/DFS
111-
112-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
113-
|-|-|-|-|-|-
114-
| 0733 |[Flood Fill](src/main/java/g0701_0800/s0733_flood_fill/Solution.java)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 1 | 85.36
115-
| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 97.76
116-
117-
#### Day 10 Dynamic Programming
118-
119-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
120-
|-|-|-|-|-|-
121-
| 0509 |[Fibonacci Number](src/main/java/g0501_0600/s0509_fibonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 0 | 100.00
122-
| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
123-
124-
#### Day 11 Dynamic Programming
125-
126-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
127-
|-|-|-|-|-|-
128-
| 0746 |[Min Cost Climbing Stairs](src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java)| Easy | Array, Dynamic_Programming | 1 | 86.38
129-
| 0062 |[Unique Paths](src/main/java/g0001_0100/s0062_unique_paths/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
130-
131-
#### Day 12 Sliding Window/Two Pointer
132-
133-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
134-
|-|-|-|-|-|-
135-
| 0438 |[Find All Anagrams in a String](src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 6 | 99.03
136-
| 0424 |[Longest Repeating Character Replacement](src/main/java/g0401_0500/s0424_longest_repeating_character_replacement/Solution.java)| Medium | String, Hash_Table, Sliding_Window | 5 | 95.15
137-
138-
#### Day 13 Hashmap
139-
140-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
141-
|-|-|-|-|-|-
142-
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 2 | 85.97
143-
| 0299 |[Bulls and Cows](src/main/java/g0201_0300/s0299_bulls_and_cows/Solution.java)| Medium | String, Hash_Table, Counting | 6 | 86.69
144-
145-
#### Day 14 Stack
146-
147-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
148-
|-|-|-|-|-|-
149-
| 0844 |[Backspace String Compare](src/main/java/g0801_0900/s0844_backspace_string_compare/Solution.java)| Easy | String, Two_Pointers, Stack, Simulation | 0 | 100.00
150-
| 0394 |[Decode String](src/main/java/g0301_0400/s0394_decode_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 1 | 87.68
151-
152-
#### Day 15 Heap
153-
154-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
155-
|-|-|-|-|-|-
156-
| 1046 |[Last Stone Weight](src/main/java/g1001_1100/s1046_last_stone_weight/Solution.java)| Easy | Array, Heap_Priority_Queue | 2 | 73.81
157-
| 0692 |[Top K Frequent Words](src/main/java/g0601_0700/s0692_top_k_frequent_words/Solution.java)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Trie, Bucket_Sort | 11 | 38.54
50+
* [Level 1](#level-1)
15851

15952
### Level 2
16053

@@ -1844,6 +1737,113 @@ implementation 'com.github.javadev:leetcode-in-java:1.34'
18441737
| 1587 |[Bank Account Summary II](src/main/java/g1501_1600/s1587_bank_account_summary_ii/script.sql)| Easy | Database | 630 | 60.32
18451738
| 1084 |[Sales Analysis III](src/main/java/g1001_1100/s1084_sales_analysis_iii/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 1066 | 69.71
18461739

1740+
### Level 1
1741+
1742+
#### Day 1 Prefix Sum
1743+
1744+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1745+
|-|-|-|-|-|-
1746+
| 1480 |[Running Sum of 1d Array](src/main/java/g1401_1500/s1480_running_sum_of_1d_array/Solution.java)| Easy | Array, Prefix_Sum | 0 | 100.00
1747+
| 0724 |[Find Pivot Index](src/main/java/g0701_0800/s0724_find_pivot_index/Solution.java)| Easy | Array, Prefix_Sum | 2 | 69.67
1748+
1749+
#### Day 2 String
1750+
1751+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1752+
|-|-|-|-|-|-
1753+
| 0205 |[Isomorphic Strings](src/main/java/g0201_0300/s0205_isomorphic_strings/Solution.java)| Easy | String, Hash_Table | 2 | 99.97
1754+
| 0392 |[Is Subsequence](src/main/java/g0301_0400/s0392_is_subsequence/Solution.java)| Easy | String, Dynamic_Programming, Two_Pointers | 1 | 93.01
1755+
1756+
#### Day 3 Linked List
1757+
1758+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1759+
|-|-|-|-|-|-
1760+
| 0021 |[Merge Two Sorted Lists](src/main/java/g0001_0100/s0021_merge_two_sorted_lists/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
1761+
| 0206 |[Reverse Linked List](src/main/java/g0201_0300/s0206_reverse_linked_list/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
1762+
1763+
#### Day 4 Linked List
1764+
1765+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1766+
|-|-|-|-|-|-
1767+
| 0876 |[Middle of the Linked List](src/main/java/g0801_0900/s0876_middle_of_the_linked_list/Solution.java)| Easy | Two_Pointers, Linked_List | 0 | 100.00
1768+
| 0142 |[Linked List Cycle II](src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
1769+
1770+
#### Day 5 Greedy
1771+
1772+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1773+
|-|-|-|-|-|-
1774+
| 0121 |[Best Time to Buy and Sell Stock](src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 100.00
1775+
| 0409 |[Longest Palindrome](src/main/java/g0401_0500/s0409_longest_palindrome/Solution.java)| Easy | String, Hash_Table, Greedy | 2 | 92.90
1776+
1777+
#### Day 6 Tree
1778+
1779+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1780+
|-|-|-|-|-|-
1781+
| 0589 |[N-ary Tree Preorder Traversal](src/main/java/g0501_0600/s0589_n_ary_tree_preorder_traversal/Solution.java)| Easy | Depth_First_Search, Tree, Stack | 1 | 90.98
1782+
| 0102 |[Binary Tree Level Order Traversal](src/main/java/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 91.09
1783+
1784+
#### Day 7 Binary Search
1785+
1786+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1787+
|-|-|-|-|-|-
1788+
| 0704 |[Binary Search](src/main/java/g0701_0800/s0704_binary_search/Solution.java)| Easy | Top_100_Liked_Questions, Array, Binary_Search | 0 | 100.00
1789+
| 0278 |[First Bad Version](src/main/java/g0201_0300/s0278_first_bad_version/Solution.java)| Easy | Binary_Search, Interactive | 15 | 87.89
1790+
1791+
#### Day 8 Binary Search Tree
1792+
1793+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1794+
|-|-|-|-|-|-
1795+
| 0098 |[Validate Binary Search Tree](src/main/java/g0001_0100/s0098_validate_binary_search_tree/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
1796+
| 0235 |[Lowest Common Ancestor of a Binary Search Tree](src/main/java/g0201_0300/s0235_lowest_common_ancestor_of_a_binary_search_tree/Solution.java)| Medium | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 4 | 100.00
1797+
1798+
#### Day 9 Graph/BFS/DFS
1799+
1800+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1801+
|-|-|-|-|-|-
1802+
| 0733 |[Flood Fill](src/main/java/g0701_0800/s0733_flood_fill/Solution.java)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 1 | 85.36
1803+
| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 97.76
1804+
1805+
#### Day 10 Dynamic Programming
1806+
1807+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1808+
|-|-|-|-|-|-
1809+
| 0509 |[Fibonacci Number](src/main/java/g0501_0600/s0509_fibonacci_number/Solution.java)| Easy | Dynamic_Programming, Math, Recursion, Memoization | 0 | 100.00
1810+
| 0070 |[Climbing Stairs](src/main/java/g0001_0100/s0070_climbing_stairs/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1811+
1812+
#### Day 11 Dynamic Programming
1813+
1814+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1815+
|-|-|-|-|-|-
1816+
| 0746 |[Min Cost Climbing Stairs](src/main/java/g0701_0800/s0746_min_cost_climbing_stairs/Solution.java)| Easy | Array, Dynamic_Programming | 1 | 86.38
1817+
| 0062 |[Unique Paths](src/main/java/g0001_0100/s0062_unique_paths/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
1818+
1819+
#### Day 12 Sliding Window/Two Pointer
1820+
1821+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1822+
|-|-|-|-|-|-
1823+
| 0438 |[Find All Anagrams in a String](src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 6 | 99.03
1824+
| 0424 |[Longest Repeating Character Replacement](src/main/java/g0401_0500/s0424_longest_repeating_character_replacement/Solution.java)| Medium | String, Hash_Table, Sliding_Window | 5 | 95.15
1825+
1826+
#### Day 13 Hashmap
1827+
1828+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1829+
|-|-|-|-|-|-
1830+
| 0001 |[Two Sum](src/main/java/g0001_0100/s0001_two_sum/Solution.java)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 2 | 85.97
1831+
| 0299 |[Bulls and Cows](src/main/java/g0201_0300/s0299_bulls_and_cows/Solution.java)| Medium | String, Hash_Table, Counting | 6 | 86.69
1832+
1833+
#### Day 14 Stack
1834+
1835+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1836+
|-|-|-|-|-|-
1837+
| 0844 |[Backspace String Compare](src/main/java/g0801_0900/s0844_backspace_string_compare/Solution.java)| Easy | String, Two_Pointers, Stack, Simulation | 0 | 100.00
1838+
| 0394 |[Decode String](src/main/java/g0301_0400/s0394_decode_string/Solution.java)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 1 | 87.68
1839+
1840+
#### Day 15 Heap
1841+
1842+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1843+
|-|-|-|-|-|-
1844+
| 1046 |[Last Stone Weight](src/main/java/g1001_1100/s1046_last_stone_weight/Solution.java)| Easy | Array, Heap_Priority_Queue | 2 | 73.81
1845+
| 0692 |[Top K Frequent Words](src/main/java/g0601_0700/s0692_top_k_frequent_words/Solution.java)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Trie, Bucket_Sort | 11 | 38.54
1846+
18471847
## Contributing
18481848
Your ideas/fixes/algorithms are more than welcome!
18491849

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package g3201_3300.s3232_find_if_digit_game_can_be_won;
2+
3+
// #Easy #Array #Math #2024_08_02_Time_0_ms_(100.00%)_Space_43.5_MB_(99.62%)
4+
5+
public class Solution {
6+
public boolean canAliceWin(int[] nums) {
7+
int sdSum = 0;
8+
int ddSum = 0;
9+
for (int num : nums) {
10+
if (num / 10 == 0) {
11+
sdSum += num;
12+
} else {
13+
ddSum += num;
14+
}
15+
}
16+
return sdSum != ddSum;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
3232\. Find if Digit Game Can Be Won
2+
3+
Easy
4+
5+
You are given an array of **positive** integers `nums`.
6+
7+
Alice and Bob are playing a game. In the game, Alice can choose **either** all single-digit numbers or all double-digit numbers from `nums`, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is **strictly greater** than the sum of Bob's numbers.
8+
9+
Return `true` if Alice can win this game, otherwise, return `false`.
10+
11+
**Example 1:**
12+
13+
**Input:** nums = [1,2,3,4,10]
14+
15+
**Output:** false
16+
17+
**Explanation:**
18+
19+
Alice cannot win by choosing either single-digit or double-digit numbers.
20+
21+
**Example 2:**
22+
23+
**Input:** nums = [1,2,3,4,5,14]
24+
25+
**Output:** true
26+
27+
**Explanation:**
28+
29+
Alice can win by choosing single-digit numbers which have a sum equal to 15.
30+
31+
**Example 3:**
32+
33+
**Input:** nums = [5,5,5,25]
34+
35+
**Output:** true
36+
37+
**Explanation:**
38+
39+
Alice can win by choosing double-digit numbers which have a sum equal to 25.
40+
41+
**Constraints:**
42+
43+
* `1 <= nums.length <= 100`
44+
* `1 <= nums[i] <= 99`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package g3201_3300.s3233_find_the_count_of_numbers_which_are_not_special;
2+
3+
// #Medium #Array #Math #Number_Theory #2024_08_02_Time_20_ms_(70.12%)_Space_44.6_MB_(17.28%)
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class Solution {
9+
public int nonSpecialCount(int l, int r) {
10+
List<Integer> primes = sieveOfEratosthenes((int) Math.sqrt(r));
11+
int specialCount = 0;
12+
13+
for (Integer prime : primes) {
14+
long primeSquare = (long) prime * prime;
15+
if (primeSquare >= l && primeSquare <= r) {
16+
specialCount++;
17+
}
18+
}
19+
20+
int totalNumbersInRange = r - l + 1;
21+
return totalNumbersInRange - specialCount;
22+
}
23+
24+
private List<Integer> sieveOfEratosthenes(int n) {
25+
boolean[] isPrime = new boolean[n + 1];
26+
for (int i = 2; i <= n; i++) {
27+
isPrime[i] = true;
28+
}
29+
30+
for (int p = 2; p * p <= n; p++) {
31+
if (isPrime[p]) {
32+
for (int i = p * p; i <= n; i += p) {
33+
isPrime[i] = false;
34+
}
35+
}
36+
}
37+
38+
List<Integer> primes = new ArrayList<>();
39+
for (int i = 2; i <= n; i++) {
40+
if (isPrime[i]) {
41+
primes.add(i);
42+
}
43+
}
44+
return primes;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
3233\. Find the Count of Numbers Which Are Not Special
2+
3+
Medium
4+
5+
You are given 2 **positive** integers `l` and `r`. For any number `x`, all positive divisors of `x` _except_ `x` are called the **proper divisors** of `x`.
6+
7+
A number is called **special** if it has exactly 2 **proper divisors**. For example:
8+
9+
* The number 4 is _special_ because it has proper divisors 1 and 2.
10+
* The number 6 is _not special_ because it has proper divisors 1, 2, and 3.
11+
12+
Return the count of numbers in the range `[l, r]` that are **not** **special**.
13+
14+
**Example 1:**
15+
16+
**Input:** l = 5, r = 7
17+
18+
**Output:** 3
19+
20+
**Explanation:**
21+
22+
There are no special numbers in the range `[5, 7]`.
23+
24+
**Example 2:**
25+
26+
**Input:** l = 4, r = 16
27+
28+
**Output:** 11
29+
30+
**Explanation:**
31+
32+
The special numbers in the range `[4, 16]` are 4 and 9.
33+
34+
**Constraints:**
35+
36+
* <code>1 <= l <= r <= 10<sup>9</sup></code>

0 commit comments

Comments
 (0)