11 DSA Problems I Practised Before My Microsoft Interview

Listen to this Post

I zeroed in on 11 essential DSA challenges that helped me crack the interview at top PBCs, and you can, too ⬇️

🔹 Arrays and Strings (Striver + CodeNCode)

🔹 Binary Search (Codeforces EDU + Yt)

🔹 Bit Manipulation (Questions Practice)

🔹 Two Pointers (Codeforces EDU)

🔹 Linked List, Stack, Queue, and BST (Striver)

🔹 Recursion & Backtracking (Striver)

🔹 Heaps & Maps (Striver + Aditya Verma for Heaps)
🔹 DP & DP with Bitmasking (Aditya Verma + Striver DP playlist)
🔹 Graphs (CodeNCode + Striver + Luv C++ Yt)
🔹 Shortest Path Algorithms (Dijkstra, Bellman Ford, Floyd Warshall)

🔹 Hamiltonian Path (directly asked in coding rounds)

Practice Verified Codes and Commands

1. Arrays and Strings


<h1>Reverse a string in Python</h1>

def reverse_string(s):
return s[::-1]

<h1>Example</h1>

print(reverse_string("hello")) # Output: "olleh"

2. Binary Search


<h1>Binary Search in Python</h1>

def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1

<h1>Example</h1>

arr = [1, 2, 3, 4, 5]
print(binary_search(arr, 3)) # Output: 2

3. Bit Manipulation


<h1>Check if a number is a power of two</h1>

def is_power_of_two(n):
return n > 0 and (n & (n - 1)) == 0

<h1>Example</h1>

print(is_power_of_two(8)) # Output: True

4. Graphs – Dijkstra’s Algorithm

import heapq

def dijkstra(graph, start):
distances = {node: float('inf') for node in graph}
distances[start] = 0
pq = [(0, start)]

while pq:
current_distance, current_node = heapq.heappop(pq)
if current_distance > distances[current_node]:
continue
for neighbor, weight in graph[current_node].items():
distance = current_distance + weight
if distance < distances[neighbor]:
distances[neighbor] = distance
heapq.heappush(pq, (distance, neighbor))
return distances

<h1>Example</h1>

graph = {
'A': {'B': 1, 'C': 4},
'B': {'A': 1, 'C': 2, 'D': 5},
'C': {'A': 4, 'B': 2, 'D': 1},
'D': {'B': 5, 'C': 1}
}
print(dijkstra(graph, 'A')) # Output: {'A': 0, 'B': 1, 'C': 3, 'D': 4}

What Undercode Say

Mastering DSA is not just about solving problems but understanding the underlying patterns and optimizations. Here are some additional Linux, IT, and Windows commands to enhance your technical skills:

1. Linux Commands

  • grep "pattern" file.txt: Search for a pattern in a file.
  • awk '{print $1}' file.txt: Print the first column of a file.
  • tar -czvf archive.tar.gz /path/to/directory: Compress a directory into a tar.gz file.
  • ps aux | grep "process_name": Find a running process by name.

2. Windows Commands

  • ipconfig: Display network configuration.
  • tasklist: List all running processes.
  • netstat -ano: Display active connections and ports.
  • sfc /scannow: Scan and repair system files.

3. IT and Cyber Commands

  • nmap -sP 192.168.1.0/24: Scan a network for live hosts.
  • tcpdump -i eth0 -w capture.pcap: Capture network traffic.
  • openssl aes-256-cbc -salt -in file.txt -out file.enc: Encrypt a file using AES-256.

For further learning, check out these resources:

By combining theoretical knowledge with practical commands and coding practice, you can excel in technical interviews and real-world challenges. Keep practicing, and remember, consistency is key!

References:

Hackers Feeds, Undercode AIFeatured Image