Leetcode with dani
Open in Telegram
Join us and let's tackle leet code questions together: improve your problem-solving skills Preparing for coding interviews learning new algorithms and data structures connect with other coding enthusiasts
Show more1 258
Subscribers
No data24 hours
+17 days
-730 days
Posts Archive
1 258
๐ต 1823. Find the Winner of the Circular Game
๐ Problem:
There are n friends sitting in a circle, numbered 1 to n.
Starting from friend 1, count k friends clockwise (including the current one).
The k-th friend leaves the circle.
Repeat the process, starting from the next friend.
The last remaining friend is the winner.
๐ Input:
n โ Number of friends.
k โ Step count for elimination.
๐ Output:
The winner's number.
๐ Example 1:
๐น Input: n = 5, k = 2
๐น Output: 3
๐น Explanation:
Friends leave in this order: 2 โ 4 โ 1 โ 5 โ (Winner: 3)
๐ Example 2:
๐น Input: n = 6, k = 5
๐น Output: 1
๐น Explanation:
Friends leave in this order: 5 โ 4 โ 6 โ 2 โ 3 โ (Winner: 1)
๐ Can you find the last friend standing? ๐
1 258
class Solution:
def countOperations(self, num1: int, num2: int) -> int:
count = 0
while num1 and num2:
if num1>=num2:
count += num1//num2
num1 = num1%num2
else:
count += num2//num1
num2 = num2%num1
return count1 258
โ2169. Count Operations to Obtain Zero
โProblem
You are given two non-negative integers,
num1 and num2. In one operation, do the following:
โข If num1 >= num2, subtract num2 from num1.
โข If num1 < num2, subtract num1 from num2.
Repeat this until either num1 or num2 becomes zero. Return the total number of operations performed.
โExamples
โExample 1
Input:
num1 = 2, num2 = 3
Output:
3
โExample 2
Input:
num1 = 10, num2 = 10
Output:
1
โConstraints
โข 0 โค num1, num2 โค 10โต1 258
Repost from Codeforces Official
Codeforces Round #1012 (Div. 1, Div. 2) will take place on the 23rd of March at 05:35 UTC.
Please, join by the link https://codeforces.com/contests/2089,2090?locale=en
1 258
Repost from Codeforces Official
Codeforces Round 1011 (Div. 2) will take place on the 22nd of March at 14:35 UTC.
Please, join by the link https://codeforces.com/contests/2085?locale=en
1 258
class Solution:
def averageOfLevels(self, root: Optional[TreeNode]) -> List[float]:
def helper(qu):
if not qu:
return
i = len(qu)
leng = len(qu)
total = 0
while i > 0:
poped = qu.popleft()
total += poped.val
if poped.left:
qu.append(poped.left)
if poped.right:
qu.append(poped.right)
i -= 1
ans.append(total/leng)
helper(qu)
qu = deque()
qu.append(root)
ans = []
helper(qu)
return ans1 258
class Solution:
def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
def helper(qu):
if not qu:
return
i = len(qu)
temp = []
nextsize = 0
while i > 0 :
poped = qu.popleft()
temp.append(poped.val)
if poped.left:
qu.append(poped.left)
nextsize += 1
if poped.right:
qu.append(poped.right)
nextsize += 1
i -= 1
ans.append(temp)
helper(qu)
if not root:
return []
ans =[]
q = deque()
q.append(root)
helper(q)
return ans1 258
102. Binary Tree Level Order Traversal
Difficulty: Medium
โProblem Statement
Given the root of a binary tree, return the level order traversal of its nodes' values (i.e., from left to right, level by level).
โExamples
Example 1:
โข Input:
root = [3,9,20,null,null,15,7]
โข Output: [[3],[9,20],[15,7]]
Example 2:
โข Input: root = [1]
โข Output: [[1]]
Example 3:
โข Input: root = []
โข Output: []
โConstraints
โข The number of nodes in the tree is in the range [0, 2000].
โข -1000 <= Node.val <= 10001 258
Here is our very first leetcode Tree problem (BFS). Answer will be posted at 6:00 PM
1 258
Here is our very first leetcode Tree problem (BFS). Answer will be posted at 6:00 PM
1 258
A big thank you to everyone at this channel and Alpha ,for a great session! I really enjoyed it.
Available now! Telegram Research 2025 โ the year's key insights 
