A big thank you to everyone at this channel and Alpha ,for a great session! I really enjoyed it.
❤7
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