Leetcode with dani
Kanalga Telegramāda oātish
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
Ko'proq ko'rsatish1 268
Obunachilar
+124 soatlar
-37 kun
-730 kun
Postlar arxiv
1 269
Repost from A2SV | Africa to Silicon Valley
In-person Conversion Registration is Open! š
Weāre excited to welcome students for the A2SV in-person conversion! This is your chance to take your learning to the next level and be part of a vibrant tech community.
Open to current students from Addis Ababa University (AAU), Addis Ababa Science and Technology University (AASTU), and Adama Science and Technology University (ASTU).
š
Registration Dates: March 24 - March 28
ā
Requirements:
- At least 150 solved problems
- At least 30 active days
š Topics to Cover: Two Pointers, Sorting, Sliding Window, Stack, Queue, Monotonicity, Linked List, Recursion.
Donāt miss this opportunityāapply now!
š Apply here: link
#A2SV #TechEducation #CodingJourney #LevelUp
1 269
Repost from Codeforces Official
Codeforces Round 1013 (Div. 3) will take place on the 25th of March at 14:35 UTC.
Please, join by the link https://codeforces.com/contests/2091?locale=en
1 269
šµ 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 269
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 269
ā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 269
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 269
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 269
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 269
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 269
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 <= 1000