Skip to content

Commit 132db74

Browse files
add 3178
1 parent 897fe6d commit 132db74

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|----------------------------------------------------------------------
11+
| 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds/) | [Java](../master/src/main/java/com/fishercoder/solutions/_3178.java) | | Easy |
1112
| 3175 | [Find The First Player to win K Games in a Row](https://leetcode.com/problems/find-the-first-player-to-win-k-games-in-a-row/) | [Java](../master/src/main/java/com/fishercoder/solutions/_3175.java) | | Medium |
1213
| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits/) | [Java](../master/src/main/java/com/fishercoder/solutions/_3174.java) | | Easy |
1314
| 3164 | [Find the Number of Good Pairs II](https://leetcode.com/problems/find-the-number-of-good-pairs-ii/) | [Java](../master/src/main/java/com/fishercoder/solutions/_3164.java) | | Medium |
@@ -235,7 +236,7 @@ _If you like this project, please leave me a star._ ★
235236
| 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_1876.java) || Easy | String |
236237
| 1874 | [Minimize Product Sum of Two Arrays](https://leetcode.com/problems/minimize-product-sum-of-two-arrays/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_1874.java) || Medium | Array, Greedy, Sorting |
237238
| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_1869.java) || Easy | Array, Two Pointers |
238-
| 1868 | [Product of Two Run-Length Encoded Arrays](https://leetcode.com/problems/product-of-two-run-length-encoded-arrays/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_1868.java) || Medium | Two Pointers |
239+
| 1868 | [Product of Two Run-Length Encoded Arrays](https://leetcode.com/problems/product-of-two-run-length-encoded-arrays/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_1868.java) || Medium | Two Pointers |
239240
| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_1863.java) || Easy | Backtracking, Recursion |
240241
| 1862 | [Sum of Floored Pairs](https://leetcode.com/problems/sum-of-floored-pairs/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_1862.java) || Hard | Math |
241242
| 1861 | [Rotating the Box](https://leetcode.com/problems/rotating-the-box/) | [Solution](../master/src/main/java/com/fishercoder/solutions/_1861.java) | [:tv:](https://youtu.be/2LRnTMOiqSI) | Medium | Array, Two Pointers |

Diff for: src/main/java/com/fishercoder/solutions/_3178.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _3178 {
4+
public static class Solution1 {
5+
public int numberOfChild(int n, int k) {
6+
//decrement by 1 to make it easier to do math so it becomes o to n - 1
7+
n--;
8+
int roundTrips = k / n;
9+
int remainingSteps = k % n;
10+
if (roundTrips % 2 == 0) {
11+
//this means it's forward direction
12+
return remainingSteps;
13+
} else {
14+
//this means it's reverse direction
15+
return n - remainingSteps;
16+
}
17+
}
18+
}
19+
}

Diff for: src/test/java/com/fishercoder/_3178Test.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._3178;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _3178Test {
10+
private static _3178.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _3178.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(1, solution1.numberOfChild(3, 5));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(2, solution1.numberOfChild(5, 6));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(2, solution1.numberOfChild(4, 2));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)