Flipkart Runway Coding Prep Expanded
Flipkart Runway Coding Prep Expanded
Input: [3, 1, 5, 9, 2]
Output: 9
Solution (Python):
def find_max(arr):
return max(arr)
arr = [3, 1, 5, 9, 2]
print(find_max(arr))
2. Strings
Strings are sequences of characters. Operations include concatenation, slicing, reversing, and
checking substrings.
Input: 'hello'
Output: 'olleh'
Solution (Python):
def reverse_string(s):
return s[::-1]
print(reverse_string('hello'))
3. Linked Lists
A Linked List is a linear data structure where each element points to the next. Common operations
Solution (Python):
class Node:
self.data = data
self.next = None
def reverse(head):
while curr:
nxt = curr.next
curr.next = prev
return prev
4. Stacks & Queues
A stack follows Last In First Out (LIFO), while a queue follows First In First Out (FIFO). Stacks are
Solution (Python):
class Stack:
def __init__(self):
self.stack = []
self.stack.append(x)
def pop(self):
s = Stack()
s.push(1)
s.push(2)
print(s.pop())
5. Recursion & Backtracking
Recursion is a function calling itself to solve subproblems. Backtracking explores possible solutions
recursively.
Input: 5
Output: 120
Solution (Python):
def factorial(n):
print(factorial(5))
6. Sorting & Searching
Sorting algorithms include Bubble Sort, Quick Sort, Merge Sort, etc. Searching includes Binary
Solution (Python):
if arr[mid] == target:
return mid
left = mid + 1
else:
right = mid - 1
return -1
print(binary_search([1,3,5,7,9], 5))
7. Dynamic Programming
Dynamic Programming (DP) solves problems by breaking them into smaller subproblems and
storing results.
Input: 6
Output: 8
Solution (Python):
if n in memo:
return memo[n]
if n <= 1:
return n
return memo[n]
print(fibonacci(6))
8. Graphs & Trees
Graphs represent relationships between nodes. Trees are a special form of graphs used in
Solution (Python):
queue = deque([start])
visited = set()
while queue:
node = queue.popleft()
visited.add(node)
queue.extend(graph[node])
bfs(graph, 0)