المنصة الأولى لتعليم البرمجة
أتقن البرمجة بالتحديات التفاعلية
انضم إلى آلاف المتعلمين في منصتنا المبتكرة التي تجمع بين الدورات المتخصصة، والتحديات البرمجية المباشرة، والمشاريع العملية
+1,000
طالب نشط
+50
مدرب خبير
+1000
ساعة تدريبية
95%
نسبة النجاح
لماذا تختار منصة WNC؟
اختبر نهجاً ثورياً في تعلم البرمجة من خلال ميزاتنا الفريدة
تحديات برمجية مباشرة
نافس زملاءك في مسابقات البرمجة المباشرة
تعلم تفاعلي
تدريبات عملية ومشاريع من الواقع
إشراف خبراء
توجيه مباشر من محترفي الصناعة
دعم وظيفي
مساعدة في التوظيف والتحضير للمقابلات
الأسئلة اليومية
تدرب على أسئلة جديدة كل يوم
| # | العنوان | اللغة | المستوى |
|---|
أنماط الخوارزميات
1#Two pointers: one input, opposite ends
2def fn(arr):
3 left = ans = 0
4 right = len(arr) - 1
5
6 while left < right:
7 # do some logic here with left and right
8 if CONDITION:
9 left += 1
10 else:
11 right -= 1
12
13 return ans
14
15
16
17
18
19
201#Two pointers: two inputs, exhaust both
2def fn(arr1, arr2):
3 i = j = ans = 0
4
5 while i < len(arr1) and j < len(arr2):
6 # do some logic here
7 if CONDITION:
8 i += 1
9 else:
10 j += 1
11
12 while i < len(arr1):
13 # do logic
14 i += 1
15
16 while j < len(arr2):
17 # do logic
18 j += 1
19 return ans
201#Sliding window
2def fn(arr):
3 left = ans = curr = 0
4
5 for right in range(len(arr)):
6 # do logic here to add arr[right] to curr
7
8 while WINDOW_CONDITION_BROKEN:
9 # remove arr[left] from curr
10 left += 1
11
12 # update ans
13
14 return ans
15
16
17
18
19
201#Build a prefix sum
2def fn(arr):
3 prefix = [arr[0]]
4 for i in range(1, len(arr)):
5 prefix.append(prefix[-1] + arr[i])
6
7 return prefix
8
9
10
11
12
13
14
15
16
17
18
19
201#Efficient string building
2# arr is a list of characters
3def fn(arr):
4 ans = []
5 for c in arr:
6 ans.append(c)
7
8 return "".join(ans)
9
10
11
12
13
14
15
16
17
18
19
201#Linked list: fast and slow pointer
2def fn(head):
3 slow = head
4 fast = head
5 ans = 0
6
7 while fast and fast.next:
8 # do logic
9 slow = slow.next
10 fast = fast.next.next
11
12 return ans
13
14
15
16
17
18
19
201#Reversing a linked list
2def fn(head):
3 curr = head
4 prev = None
5 while curr:
6 next_node = curr.next
7 curr.next = prev
8 prev = curr
9 curr = next_node
10
11 return prev
12
13
14
15
16
17
18
19
201#Find number of subarrays that fit an exact criteria
2from collections import defaultdict
3
4def fn(arr, k):
5 counts = defaultdict(int)
6 counts[0] = 1
7 ans = curr = 0
8
9 for num in arr:
10 # do logic to change curr
11 ans += counts[curr - k]
12 counts[curr] += 1
13
14 return ans
15
16
17
18
19
201#Monotonic increasing stack
2#The same logic can be applied to maintain a monotonic queue.
3public int fn(int[] arr) {
4 Stack<Integer> stack = new Stack<>();
5 int ans = 0;
6
7 for (int num: arr) {
8 // for monotonic decreasing, just flip the > to <
9 while (!stack.empty() && stack.peek() > num) {
10 // do logic
11 stack.pop();
12 }
13
14 stack.push(num);
15 }
16
17 return ans;
18
19
20
21
22}
231#Binary tree: DFS (recursive)
2public int dfs(TreeNode root) {
3 if (root == null) {
4 return 0;
5 }
6
7 int ans = 0;
8 // do logic
9 dfs(root.left);
10 dfs(root.right);
11 return ans;
12}
13
14
15
16
17
18
19
20
21
22
231#Binary tree: DFS (iterative)
2public int dfs(TreeNode root) {
3 Stack<TreeNode> stack = new Stack<>();
4 stack.push(root);
5 int ans = 0;
6
7 while (!stack.empty()) {
8 TreeNode node = stack.pop();
9 // do logic
10 if (node.left != null) {
11 stack.push(node.left);
12 }
13 if (node.right != null) {
14 stack.push(node.right);
15 }
16 }
17
18 return ans;
19
20
21
22}
231#Binary tree: BFS
2public int fn(TreeNode root) {
3 Queue<TreeNode> queue = new LinkedList<>();
4 queue.add(root);
5 int ans = 0;
6
7 while (!queue.isEmpty()) {
8 int currentLength = queue.size();
9 // do logic for current level
10 for (int i = 0; i < currentLength; i++) {
11 TreeNode node = queue.remove();
12 // do logic
13 if (node.left != null) {
14 queue.add(node.left);
15 }
16 if (node.right != null) {
17 queue.add(node.right);
18 }
19 }
20 }
21 return ans;
22}
231#Graph: DFS (recursive)
2Set<Integer> seen = new HashSet<>();
3
4public int fn(int[][] graph) {
5 seen.add(START_NODE);
6 return dfs(START_NODE, graph);
7}
8
9public int dfs(int node, int[][] graph) {
10 int ans = 0;
11 // do some logic
12 for (int neighbor: graph[node]) {
13 if (!seen.contains(neighbor)) {
14 seen.add(neighbor);
15 ans += dfs(neighbor, graph);
16 }
17 }
18
19 return ans;
20
21
22}
231#Graph: DFS (iterative)
2public int fn(int[][] graph) {
3 Stack<Integer> stack = new Stack<>();
4 Set<Integer> seen = new HashSet<>();
5 stack.push(START_NODE);
6 seen.add(START_NODE);
7 int ans = 0;
8
9 while (!stack.empty()) {
10 int node = stack.pop();
11 // do some logic
12 for (int neighbor: graph[node]) {
13 if (!seen.contains(neighbor)) {
14 seen.add(neighbor);
15 stack.push(neighbor);
16 }
17 }
18 }
19
20 return ans;
21
22}
231#Find top k elements with heap
2public int[] fn(int[] arr, int k) {
3 PriorityQueue<Integer> heap = new PriorityQueue<>(CRITERIA);
4 for (int num: arr) {
5 heap.add(num);
6 if (heap.size() > k) {
7 heap.remove();
8 }
9 }
10
11 int[] ans = new int[k];
12 for (int i = 0; i < k; i++) {
13 ans[i] = heap.remove();
14 }
15
16 return ans;
17}
18
19
20
21
22
231#Graph: BFS
2public int fn(int[][] graph) {
3 Queue<Integer> queue = new LinkedList<>();
4 Set<Integer> seen = new HashSet<>();
5 queue.add(START_NODE);
6 seen.add(START_NODE);
7 int ans = 0;
8
9 while (!queue.isEmpty()) {
10 int node = queue.remove();
11 // do some logic
12 for (int neighbor: graph[node]) {
13 if (!seen.contains(neighbor)) {
14 seen.add(neighbor);
15 queue.add(neighbor);
16 }
17 }
18 }
19
20 return ans;
21
22}
23هل أنت مستعد لبدء رحلتك؟
انضم إلى آلاف المبرمجين الناجحين الذين بدأوا مسيرتهم المهنية مع WNC