2026 January 10 Problems

77 views
Skip to first unread message

daryl...@gmail.com

unread,
Jan 10, 2026, 12:48:07 PMJan 10
to leetcode-meetup
Feel free to work on any of the problems you want; we'll have people present their solutions at 11:30.

Please post your solutions to this thread so others can use this as a reference.

1025. Divisor Game Easy 71.3%




We're going to use the same Google meet link as the last few times: https://meet.google.com/xnn-kifj-jnx?pli=1


Anuj Patnaik

unread,
Jan 10, 2026, 12:59:52 PMJan 10
to leetcode-meetup
class Solution:
def divisorGame(self, n: int) -> bool:
return n % 2 == 0

Anuj Patnaik

unread,
Jan 10, 2026, 1:03:02 PMJan 10
to leetcode-meetup
class Solution:
def totalWaviness(self, num1: int, num2: int) -> int:
total_waviness = 0
for i in range(num1, num2 + 1):
str_i = str(i)
if len(str_i) < 3:
continue
else:
for j in range(1, len(str_i) - 1):
if (str_i[j] > str_i[j-1] and str_i[j] > str_i[j + 1]) or (str_i[j] < str_i[j-1] and str_i[j] < str_i[j + 1]):
total_waviness += 1
return total_waviness

Allen S.

unread,
Jan 10, 2026, 1:06:52 PMJan 10
to leetcode-meetup
func divisorGame(n int) bool {
// odd - loses
// even - wins
return n % 2 == 0
}
On Saturday, January 10, 2026 at 9:48:07 AM UTC-8 daryl...@gmail.com wrote:

FloM

unread,
Jan 10, 2026, 1:29:27 PMJan 10
to leetcode-meetup
1025. Divisor Game Easy 71.3%
class Solution {
public:
bool divisorGame(int n) {
// Given: If a player gets n = 2. Then they win.
// If a player gets n = 1, they lose.
// If a player gets an even number, they can always make the other player get an odd number by choosing x = 1.
// If a player get an odd number they can not force the other player to get an odd number. No odd number is divisible by 2, and an x of 2 would is required to make an odd n even.
// If Alice gets an even number she can whittle down n until it is a one, giving Bob an odd number by chosing x = 1.
return (n % 2 == 0);
}
};

Allen S.

unread,
Jan 10, 2026, 1:30:55 PMJan 10
to leetcode-meetup
func totalWaviness(num1 int, num2 int) int { // linear time
totalWavecount := 0
for num := num1; num <= num2; num++ {
totalWavecount += waveCount(num)
}
return totalWavecount
}

func waveCount(num int) int { // log time
count := 0
q := []int{}
for ; num > 0; num /= 10 {
d := num % 10
q = append(q, d)
if len(q) == 3 {
if q[0] < q[1] && q[1] > q[2] {
count++
}
if q[0] > q[1] && q[1] < q[2] {
count++
}
q = q[1:]
}
}
return count
}

On Saturday, January 10, 2026 at 9:48:07 AM UTC-8 daryl...@gmail.com wrote:

Rag Mur

unread,
Jan 10, 2026, 2:20:50 PMJan 10
to leetcode-meetup
class Solution:
def divisorGame(self, n: int) -> bool:
'''
This is like UNO game where if you force the opponent to always pass you an even number. And finaly you can will
Anyone who gets even number on their turn can win of they play optimally do to the math series of the game. here is the proof
End result | Number | Possible number that can be passed to opponent after their turn
Loose 1 end of game the player loose
win 2 1
loose 3 2
win 4 2,3 (the current player must pass odd if they need to win)
loose 5 4
win 6 5, 3, 2
loose 7 6
win 8 7, 6, 4
.... and so on till infinity

'''
return n % 2 == 0
1025. Divisor Game Easy 71.3%


class Solution:
def totalWaviness(self, num1: int, num2: int) -> int:
'''
12345
123 234 345

1234
123 234

123
434
'''
total = 0
for num in range(num1, num2 + 1):
s = str(num)
# A number must have at least 3 digits to have a peak or valley
if len(s) < 3:
continue
# Check every digit except the first and last
for i in range(1, len(s) - 1):
if (s[i-1] < s[i] > s[i+1]) or (s[i-1] > s[i] < s[i+1]):
total += 1
return total

On Saturday, January 10, 2026 at 9:48:07 AM UTC-8 daryl...@gmail.com wrote:

saurabh sharma

unread,
Jan 10, 2026, 2:33:49 PMJan 10
to leetcode-meetup
class Solution:
def divisorGame(self, n: int) -> bool:
return n%2 == 0

On Saturday, January 10, 2026 at 9:48:07 AM UTC-8 daryl...@gmail.com wrote:

saurabh sharma

unread,
Jan 10, 2026, 2:33:59 PMJan 10
to leetcode-meetup
class Solution:
def totalWaviness(self, num1: int, num2: int) -> int:
waviness = 0
return sum(self.get_waviness(num) for num in range(num1, num2+1))

def get_waviness(self, num):
if num < 100:
return 0

nums = str(num)
waviness = 0

for i in range (1, len(nums)-1):
if nums[i] > nums[i-1] and nums[i] > nums[i+1]:
waviness += 1
elif nums[i] < nums[i-1] and nums[i] < nums[i+1]:
waviness += 1
return waviness

On Saturday, January 10, 2026 at 9:48:07 AM UTC-8 daryl...@gmail.com wrote:

Wang Lijun

unread,
Jan 10, 2026, 4:38:58 PMJan 10
to leetcode-meetup
```
class Solution:
def getW(self, digits):
res = 0
n = len(digits)
for l in range(n - 2):
m = l+1
r = l+2
if digits[l] < digits[m] > digits[r] or digits[l] > digits[m] < digits[r]:
res += 1
return res

def totalWaviness(self, num1: int, num2: int) -> int:
res = 0
for num in range(num1, num2+1):
digits = []
x = num
while x > 0:
digits.append(x % 10)
x = x // 10
res += self.getW(digits)
return res
```

Rag Mur

unread,
Jan 21, 2026, 8:52:21 AMJan 21
to leetcode-meetup
Its took a while to build up the intuition for this problem (and some Leetcode discussions)

This problem uses a two patterns
  1. [Pat_1] - totalWaviness between two number  = wavinessCount from num2 - wavinessCount from num1-1
  2. [Pat_2] tight and started pattern
and here is how you build the intuition to use above two
  1. Realizing  pat_1 is super easy its just put math question
  2. How to arrive at Pat_2:
    1. Problem say num2 max 10^15 . Even iterating from 0 to 10^15 will cause TLE. So, the solution must use some sort traversal overs digits
    2.  tight: Problem says we have to count upto certain num. So, when iterating over digit in order to ensure we are not exceeding num we can use a bool flag, which is `tight`
    3.  Started: this flag is used to track is the previously placed numbers are 0. And if not started, don't factor in waviness of number placed in current dp iteration. 
    4. Finally add other accessories like tracking previous 2 numbers, logic to calculate waviness, and  lru_cache for performance.
  3. Further read on this pattern

from functools import lru_cache

class Solution:
def totalWaviness(self, num1: int, num2: int) -> int:
def countWaviness(num):
num_string = str(num)
num_length = len(num_string)
@lru_cache(None)
def dp(i, prev1, prev2, tight, started):
# returns total number found and total waviness
if i == num_length:
return (1, 0) # there is one number that completed and not further waviness since the number ended
max_allowed_num_for_digit = int(num_string[i]) if tight else 9
total_count, total_waviness = 0, 0

for new_digit in range(max_allowed_num_for_digit+1):
new_started = started or (new_digit != 0)
new_tight = tight & (new_digit == int(num_string[i]))
current_waviness = (started and prev1 != -1 and prev2 != -1) and ((prev1 < prev2 > new_digit) or (prev1 > prev2 < new_digit))
if not new_started:
child_count, child_waviness = dp(i+1, -1, -1, new_tight, new_started)
total_waviness += child_waviness
total_count += child_count
else:
child_count, child_waviness = dp(i+1, prev2, new_digit, new_tight, new_started)
total_waviness += (child_waviness + child_count if current_waviness else child_waviness)
total_count += child_count

return (total_count, total_waviness)

return dp(0, -1, -1, True, False)[1]
return countWaviness(num2) - countWaviness(num1-1)
Reply all
Reply to author
Forward
0 new messages