File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 2138
2138
3025|[ Find the Number of Ways to Place People I] ( ./solutions/3025-find-the-number-of-ways-to-place-people-i.js ) |Medium|
2139
2139
3027|[ Find the Number of Ways to Place People II] ( ./solutions/3027-find-the-number-of-ways-to-place-people-ii.js ) |Hard|
2140
2140
3028|[ Ant on the Boundary] ( ./solutions/3028-ant-on-the-boundary.js ) |Easy|
2141
+ 3029|[ Minimum Time to Revert Word to Initial State I] ( ./solutions/3029-minimum-time-to-revert-word-to-initial-state-i.js ) |Medium|
2141
2142
3042|[ Count Prefix and Suffix Pairs I] ( ./solutions/3042-count-prefix-and-suffix-pairs-i.js ) |Easy|
2142
2143
3066|[ Minimum Operations to Exceed Threshold Value II] ( ./solutions/3066-minimum-operations-to-exceed-threshold-value-ii.js ) |Medium|
2143
2144
3068|[ Find the Maximum Sum of Node Values] ( ./solutions/3068-find-the-maximum-sum-of-node-values.js ) |Hard|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 3029. Minimum Time to Revert Word to Initial State I
3
+ * https://leetcode.com/problems/minimum-time-to-revert-word-to-initial-state-i/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given a 0-indexed string word and an integer k.
7
+ *
8
+ * At every second, you must perform the following operations:
9
+ * - Remove the first k characters of word.
10
+ * - Add any k characters to the end of word.
11
+ *
12
+ * Note that you do not necessarily need to add the same characters that you removed.
13
+ * However, you must perform both operations at every second.
14
+ *
15
+ * Return the minimum time greater than zero required for word to revert to its initial state.
16
+ */
17
+
18
+ /**
19
+ * @param {string } word
20
+ * @param {number } k
21
+ * @return {number }
22
+ */
23
+ var minimumTimeToInitialState = function ( word , k ) {
24
+ const n = word . length ;
25
+
26
+ for ( let i = 1 ; i * k <= n ; i ++ ) {
27
+ if ( word . slice ( i * k ) === word . slice ( 0 , n - i * k ) ) {
28
+ return i ;
29
+ }
30
+ }
31
+
32
+ return Math . ceil ( n / k ) ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments