Skip to content

Commit c0b8edb

Browse files
committed
Added tasks 257-290.
1 parent 7ab9167 commit c0b8edb

File tree

18 files changed

+1211
-0
lines changed

18 files changed

+1211
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
6363
|-|-|-|-|-|-
6464
| 0240 |[Search a 2D Matrix II](src/main/kotlin/g0201_0300/s0240_search_a_2d_matrix_ii)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer | 460 | 66.08
65+
| 0275 |[H-Index II](src/main/kotlin/g0201_0300/s0275_h_index_ii)| Medium | Array, Binary_Search | 398 | 81.82
6566

6667
#### Day 9
6768

@@ -195,6 +196,7 @@
195196

196197
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
197198
|-|-|-|-|-|-
199+
| 0264 |[Ugly Number II](src/main/kotlin/g0201_0300/s0264_ugly_number_ii)| Medium | Hash_Table, Dynamic_Programming, Math, Heap_Priority_Queue | 182 | 95.45
198200
| 0096 |[Unique Binary Search Trees](src/main/kotlin/g0001_0100/s0096_unique_binary_search_trees)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree | 147 | 88.52
199201

200202
#### Day 12
@@ -258,6 +260,7 @@
258260

259261
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
260262
|-|-|-|-|-|-
263+
| 0279 |[Perfect Squares](src/main/kotlin/g0201_0300/s0279_perfect_squares)| Medium | Top_Interview_Questions, Dynamic_Programming, Math, Breadth_First_Search | 176 | 98.80
261264

262265
### Programming Skills I
263266

@@ -622,6 +625,7 @@
622625

623626
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
624627
|-|-|-|-|-|-
628+
| 0278 |[First Bad Version](src/main/kotlin/g0201_0300/s0278_first_bad_version)| Easy | Binary_Search, Interactive | 349 | 76.86
625629

626630
#### Day 8 Binary Search Tree
627631

@@ -834,6 +838,7 @@
834838
| 0242 |[Valid Anagram](src/main/kotlin/g0201_0300/s0242_valid_anagram)| Easy | Top_Interview_Questions, String, Hash_Table, Sorting | 251 | 87.65
835839
| 0049 |[Group Anagrams](src/main/kotlin/g0001_0100/s0049_group_anagrams)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting | 506 | 86.55
836840
| 0151 |[Reverse Words in a String](src/main/kotlin/g0101_0200/s0151_reverse_words_in_a_string)| Medium | String, Two_Pointers | 206 | 98.90
841+
| 0273 |[Integer to English Words](src/main/kotlin/g0201_0300/s0273_integer_to_english_words)| Hard | String, Math, Recursion | 273 | 82.93
837842

838843
#### Udemy Binary Search
839844

@@ -1132,6 +1137,7 @@
11321137

11331138
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11341139
|-|-|-|-|-|-
1140+
| 0290 |[Word Pattern](src/main/kotlin/g0201_0300/s0290_word_pattern)| Easy | String, Hash_Table | 177 | 89.55
11351141
| 0763 |[Partition Labels](src/main/kotlin/g0701_0800/s0763_partition_labels)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers | 235 | 84.75
11361142

11371143
#### Day 8 String
@@ -1232,6 +1238,7 @@
12321238

12331239
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12341240
|-|-|-|-|-|-
1241+
| 0278 |[First Bad Version](src/main/kotlin/g0201_0300/s0278_first_bad_version)| Easy | Binary_Search, Interactive | 349 | 76.86
12351242
| 0035 |[Search Insert Position](src/main/kotlin/g0001_0100/s0035_search_insert_position)| Easy | Top_100_Liked_Questions, Array, Binary_Search | 267 | 50.32
12361243

12371244
#### Day 2 Two Pointers
@@ -1487,6 +1494,7 @@
14871494

14881495
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
14891496
|-|-|-|-|-|-
1497+
| 0278 |[First Bad Version](src/main/kotlin/g0201_0300/s0278_first_bad_version)| Easy | Binary_Search, Interactive | 349 | 76.86
14901498
| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/kotlin/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search | 228 | 83.38
14911499

14921500
#### Day 6
@@ -1551,8 +1559,24 @@
15511559
| 0322 |[Coin Change](src/main/kotlin/g0301_0400/s0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_20, Level_2_Day_12_Dynamic_Programming | 332 | 50.68
15521560
| 0300 |[Longest Increasing Subsequence](src/main/kotlin/g0201_0300/s0300_longest_increasing_subsequence)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Algorithm_II_Day_16_Dynamic_Programming, Binary_Search_II_Day_3, Dynamic_Programming_I_Day_18, Udemy_Dynamic_Programming | 318 | 82.28
15531561
| 0295 |[Find Median from Data Stream](src/main/kotlin/g0201_0300/s0295_find_median_from_data_stream)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream | 2289 | 33.60
1562+
| 0290 |[Word Pattern](src/main/kotlin/g0201_0300/s0290_word_pattern)| Easy | String, Hash_Table, Data_Structure_II_Day_7_String | 177 | 89.55
1563+
| 0289 |[Game of Life](src/main/kotlin/g0201_0300/s0289_game_of_life)| Medium | Top_Interview_Questions, Array, Matrix, Simulation | 174 | 96.97
15541564
| 0287 |[Find the Duplicate Number](src/main/kotlin/g0201_0300/s0287_find_the_duplicate_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Binary_Search_II_Day_5 | 656 | 66.21
1565+
| 0284 |[Peeking Iterator](src/main/kotlin/g0201_0300/s0284_peeking_iterator)| Medium | Array, Design, Iterator | 286 | 62.50
15551566
| 0283 |[Move Zeroes](src/main/kotlin/g0201_0300/s0283_move_zeroes)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Two_Pointers, Algorithm_I_Day_3_Two_Pointers, Programming_Skills_I_Day_6_Array, Udemy_Arrays | 516 | 79.07
1567+
| 0282 |[Expression Add Operators](src/main/kotlin/g0201_0300/s0282_expression_add_operators)| Hard | String, Math, Backtracking | 367 | 85.71
1568+
| 0279 |[Perfect Squares](src/main/kotlin/g0201_0300/s0279_perfect_squares)| Medium | Top_Interview_Questions, Dynamic_Programming, Math, Breadth_First_Search, Dynamic_Programming_I_Day_21 | 176 | 98.80
1569+
| 0278 |[First Bad Version](src/main/kotlin/g0201_0300/s0278_first_bad_version)| Easy | Binary_Search, Interactive, Algorithm_I_Day_1_Binary_Search, Binary_Search_I_Day_5, Level_1_Day_7_Binary_Search | 349 | 76.86
1570+
| 0275 |[H-Index II](src/main/kotlin/g0201_0300/s0275_h_index_ii)| Medium | Array, Binary_Search, Binary_Search_II_Day_8 | 398 | 81.82
1571+
| 0274 |[H-Index](src/main/kotlin/g0201_0300/s0274_h_index)| Medium | Array, Sorting, Counting_Sort | 291 | 45.45
1572+
| 0273 |[Integer to English Words](src/main/kotlin/g0201_0300/s0273_integer_to_english_words)| Hard | String, Math, Recursion, Udemy_Strings | 273 | 82.93
1573+
| 0268 |[Missing Number](src/main/kotlin/g0201_0300/s0268_missing_number)| Easy | Top_Interview_Questions, Array, Hash_Table, Math, Sorting, Binary_Search, Bit_Manipulation | 380 | 83.49
1574+
| 0264 |[Ugly Number II](src/main/kotlin/g0201_0300/s0264_ugly_number_ii)| Medium | Hash_Table, Dynamic_Programming, Math, Heap_Priority_Queue, Dynamic_Programming_I_Day_11 | 182 | 95.45
1575+
| 0263 |[Ugly Number](src/main/kotlin/g0201_0300/s0263_ugly_number)| Easy | Math | 243 | 64.10
1576+
| 0262 |[Trips and Users](src/main/kotlin/g0201_0300/s0262_trips_and_users)| Hard | Database | 577 | 63.97
1577+
| 0260 |[Single Number III](src/main/kotlin/g0201_0300/s0260_single_number_iii)| Medium | Array, Bit_Manipulation | 222 | 100.00
1578+
| 0258 |[Add Digits](src/main/kotlin/g0201_0300/s0258_add_digits)| Easy | Math, Simulation, Number_Theory | 234 | 71.64
1579+
| 0257 |[Binary Tree Paths](src/main/kotlin/g0201_0300/s0257_binary_tree_paths)| Easy | String, Depth_First_Search, Tree, Binary_Tree, Backtracking | 320 | 72.84
15561580
| 0242 |[Valid Anagram](src/main/kotlin/g0201_0300/s0242_valid_anagram)| Easy | Top_Interview_Questions, String, Hash_Table, Sorting, Data_Structure_I_Day_6_String, Programming_Skills_I_Day_11_Containers_and_Libraries, Udemy_Strings | 251 | 87.65
15571581
| 0241 |[Different Ways to Add Parentheses](src/main/kotlin/g0201_0300/s0241_different_ways_to_add_parentheses)| Medium | String, Dynamic_Programming, Math, Recursion, Memoization | 294 | 73.47
15581582
| 0240 |[Search a 2D Matrix II](src/main/kotlin/g0201_0300/s0240_search_a_2d_matrix_ii)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Data_Structure_II_Day_4_Array, Binary_Search_II_Day_8 | 460 | 66.08

src/main/kotlin/g0101_0200/s0177_nth_highest_salary/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ DECLARE M INT;
7272
SET M=N-1;
7373
RETURN (
7474
# Write your MySQL query statement below.
75+
# #Medium #Database #2022_10_18_Time_338_ms_(86.68%)_Space_0B_(100.00%)
7576
SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M, 1
7677
);
7778
END
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 257\. Binary Tree Paths
5+
6+
Easy
7+
8+
Given the `root` of a binary tree, return _all root-to-leaf paths in **any order**_.
9+
10+
A **leaf** is a node with no children.
11+
12+
**Example 1:**
13+
14+
![](https://assets.leetcode.com/uploads/2021/03/12/paths-tree.jpg)
15+
16+
**Input:** root = [1,2,3,null,5]
17+
18+
**Output:** ["1->2->5","1->3"]
19+
20+
**Example 2:**
21+
22+
**Input:** root = [1]
23+
24+
**Output:** ["1"]
25+
26+
**Constraints:**
27+
28+
* The number of nodes in the tree is in the range `[1, 100]`.
29+
* `-100 <= Node.val <= 100`
30+
31+
## Solution
32+
33+
```kotlin
34+
import com_github_leetcode.TreeNode
35+
36+
/*
37+
* Example:
38+
* var ti = TreeNode(5)
39+
* var v = ti.`val`
40+
* Definition for a binary tree node.
41+
* class TreeNode(var `val`: Int) {
42+
* var left: TreeNode? = null
43+
* var right: TreeNode? = null
44+
* }
45+
*/
46+
class Solution {
47+
private var result: MutableList<String>? = null
48+
private var sb: StringBuilder? = null
49+
fun binaryTreePaths(root: TreeNode?): List<String> {
50+
result = ArrayList()
51+
if (root == null) {
52+
return result as ArrayList<String>
53+
}
54+
sb = StringBuilder()
55+
walkThrough(root)
56+
return result as ArrayList<String>
57+
}
58+
59+
private fun walkThrough(root: TreeNode?) {
60+
assert(root != null)
61+
var length = sb!!.length
62+
sb!!.append(root!!.`val`)
63+
length = sb!!.length - length
64+
if (root.left == null && root.right == null) {
65+
// leaf node.
66+
result!!.add(sb.toString())
67+
sb!!.delete(sb!!.length - length, sb!!.length)
68+
return
69+
}
70+
sb!!.append("->")
71+
length += 2
72+
if (root.left != null) {
73+
walkThrough(root.left)
74+
}
75+
if (root.right != null) {
76+
walkThrough(root.right)
77+
}
78+
sb!!.delete(sb!!.length - length, sb!!.length)
79+
}
80+
}
81+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 258\. Add Digits
5+
6+
Easy
7+
8+
Given an integer `num`, repeatedly add all its digits until the result has only one digit, and return it.
9+
10+
**Example 1:**
11+
12+
**Input:** num = 38
13+
14+
**Output:** 2
15+
16+
**Explanation:** The process is 38 --> 3 + 8 --> 11 11 --> 1 + 1 --> 2 Since 2 has only one digit, return it.
17+
18+
**Example 2:**
19+
20+
**Input:** num = 0
21+
22+
**Output:** 0
23+
24+
**Constraints:**
25+
26+
* <code>0 <= num <= 2<sup>31</sup> - 1</code>
27+
28+
**Follow up:** Could you do it without any loop/recursion in `O(1)` runtime?
29+
30+
## Solution
31+
32+
```kotlin
33+
class Solution {
34+
fun addDigits(num: Int): Int {
35+
if (num == 0) {
36+
return 0
37+
}
38+
return if (num % 9 == 0) {
39+
9
40+
} else num % 9
41+
}
42+
}
43+
```
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-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 260\. Single Number III
5+
6+
Medium
7+
8+
Given an integer array `nums`, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in **any order**.
9+
10+
You must write an algorithm that runs in linear runtime complexity and uses only constant extra space.
11+
12+
**Example 1:**
13+
14+
**Input:** nums = [1,2,1,3,2,5]
15+
16+
**Output:** [3,5] **Explanation: ** [5, 3] is also a valid answer.
17+
18+
**Example 2:**
19+
20+
**Input:** nums = [-1,0]
21+
22+
**Output:** [-1,0]
23+
24+
**Example 3:**
25+
26+
**Input:** nums = [0,1]
27+
28+
**Output:** [1,0]
29+
30+
**Constraints:**
31+
32+
* <code>2 <= nums.length <= 3 * 10<sup>4</sup></code>
33+
* <code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code>
34+
* Each integer in `nums` will appear twice, only two integers will appear once.
35+
36+
## Solution
37+
38+
```kotlin
39+
class Solution {
40+
fun singleNumber(nums: IntArray): IntArray {
41+
var xorSum = 0
42+
for (num in nums) {
43+
// will give xor of required nos
44+
xorSum = xorSum xor num
45+
}
46+
// find rightmost bit which is set
47+
val rightBit = xorSum and -xorSum
48+
var a = 0
49+
for (num in nums) {
50+
// xor only those number whose rightmost bit is set
51+
if (num and rightBit != 0) {
52+
a = a xor num
53+
}
54+
}
55+
return intArrayOf(a, a xor xorSum)
56+
}
57+
}
58+
```

0 commit comments

Comments
 (0)