Here is our very first leetcode Tree problem (BFS). Answer will be posted at 6:00 PM
LeetCode
Binary Tree Level Order Traversal - LeetCode
Can you solve this real interview question? Binary Tree Level Order Traversal - 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).
Example 1:
[https://assets.leetcode.cβ¦
Example 1:
[https://assets.leetcode.cβ¦
π3
Leetcode with dani
Here is our very first leetcode Tree problem (BFS). Answer will be posted at 6:00 PM
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:
β’ Output:
Example 2:
β’ Input:
β’ Output:
Example 3:
β’ Input:
β’ Output:
βConstraints
β’ The number of nodes in the tree is in the range
β’
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
Leetcode with dani
Here is our very first leetcode Tree problem (BFS). Answer will be posted at 6:00 PM
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 ans
β€1
#Tree second question Answer will be posted at 4 PM
LeetCode
Average of Levels in Binary Tree - LeetCode
Can you solve this real interview question? Average of Levels in Binary Tree - Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer will be accepted.
Exampleβ¦
Exampleβ¦
π3
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 ans
π2β1
Forwarded 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
Please, join by the link https://codeforces.com/contests/2085?locale=en
Codeforces
Codeforces Round 1011 (Div. 2) - Codeforces
Codeforces. Programming competitions and contests, programming community
Forwarded 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
Please, join by the link https://codeforces.com/contests/2089,2090?locale=en
Codeforces
Codeforces Round 1012 - Codeforces
Codeforces. Programming competitions and contests, programming community
β2169. Count Operations to Obtain Zero
βProblem
You are given two non-negative integers,
β’ If
β’ If
Repeat this until either
βExamples
βExample 1
Input:
Output:
βExample 2
Input:
Output:
βConstraints
β’ 0 β€ num1, num2 β€ 10β΅
β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β΅
LeetCode
Count Operations to Obtain Zero - LeetCode
Can you solve this real interview question? Count Operations to Obtain Zero - You are given two non-negative integers num1 and num2.
In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.
* For example,β¦
In one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.
* For example,β¦
Leetcode with dani
β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β¦
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 count
π΅ 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? π
π 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? π
Leetcode with dani
π΅ 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β¦
LeetCode
Find the Winner of the Circular Game - LeetCode
Can you solve this real interview question? Find the Winner of the Circular Game - There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ithβ¦
Forwarded 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
Please, join by the link https://codeforces.com/contests/2091?locale=en
Codeforces
Codeforces Round 1013 (Div. 3) - Codeforces
Codeforces. Programming competitions and contests, programming community
Forwarded 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
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
π5
Forwarded from Codeforces Official
Codeforces Round 1014 (Div. 2) will take place on the 29th of March at 14:35 UTC.
Please, join by the link https://codeforces.com/contests/2092?locale=en
Please, join by the link https://codeforces.com/contests/2092?locale=en
Codeforces
Codeforces Round 1014 (Div. 2) - Codeforces
Codeforces. Programming competitions and contests, programming community