0% found this document useful (0 votes)
27 views12 pages

3 Meadows Coding Questions

The document presents 50 coding scenarios covering various data structures and algorithms, including tasks related to arrays, linked lists, stacks, queues, sorting, searching, and object-oriented programming. Each scenario includes a problem statement, input examples, and expected output. The problems are designed to test and improve coding skills in a range of programming concepts.

Uploaded by

mani pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views12 pages

3 Meadows Coding Questions

The document presents 50 coding scenarios covering various data structures and algorithms, including tasks related to arrays, linked lists, stacks, queues, sorting, searching, and object-oriented programming. Each scenario includes a problem statement, input examples, and expected output. The problems are designed to test and improve coding skills in a range of programming concepts.

Uploaded by

mani pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

3 Meadows Coding Questions

1. Scenario: Find the Missing Number in a Sequence

Problem:
You’re working at a warehouse that tracks the IDs of packages arriving each day. The system assigns
sequential numbers from 1 to n for each day's arrivals, but due to a system glitch, one number is
missing. Write a program that finds the missing number.

Input:
arr = [1, 2, 3, 5]
Expected Output:
4

2. Scenario: Move All Zeroes to End

Problem:
In a mobile game, scores of zero represent fouls. You’re given an array of scores and need to shift all
fouls (zeroes) to the end while maintaining the order of the other scores.

Input:
arr = [0, 1, 0, 3, 12]
Expected Output:
[1, 3, 12, 0, 0]

3. Scenario: Reverse a Linked List

Problem:
You’re implementing a basic text editor undo functionality. Every action is stored as a linked list. To
undo, you need to reverse the list of actions.

Input:
1 → 2 → 3 → 4 → NULL
Expected Output:
4 → 3 → 2 → 1 → NULL

4. Scenario: Detect a Cycle in a Linked List

Problem:
In a GPS tracking system, the route data is stored in a linked list. If a location appears twice without
arriving back at the start, it might indicate a looped path. Write a program to detect a loop.

Input:
1 → 2 → 3 → 4 → 2 (loop back to 2)
Expected Output:
True
5. Scenario: Allocate Memory for Student Records

Problem:
You are designing a student management system where student records are dynamically created as
students enroll. Write a C program to dynamically allocate memory for storing marks of n students
using malloc.

Input:
n = 3, marks = 45, 56, 89
Expected Output:
Memory allocated and printed:
45 56 89

6. Scenario: Print Array Using Pointer Arithmetic

Problem:
You’ve been asked to train new interns on pointer basics. Write a C program to read 5 integers into an
array and print them using only pointer arithmetic (no array indexing).

Input:
arr = [10, 20, 30, 40, 50]
Expected Output:
10 20 30 40 50

7. Scenario: Find the Longest Increasing Subsequence

Problem:
A stock analyst wants to find the longest period during which stock prices have increased day-by-day.
Given an array of stock prices, return the length of the longest increasing subsequence.

Input:
[10, 9, 2, 5, 3, 7, 101, 18]
Expected Output:
4 ([2, 3, 7, 101])

8. Scenario: Build a Tree of Categories

Problem:
An e-commerce website uses a binary tree structure to organize its categories (e.g., Electronics →
Phones, Laptops). Write a program to construct the tree and perform an inorder traversal to list all
categories.

Input (tree):

markdown
Electronics
/ \
Phones Laptops

Expected Output (inorder):


Phones Electronics Laptops

9. Scenario: Preventing Deadlock in Banking App

Problem:
You are developing a banking app where customers can transfer funds. Explain with a code snippet
how to avoid deadlocks when two users try to transfer funds to each other simultaneously.

Input:
Accounts A and B trying to lock each other
Expected Output:
Proper ordering of lock acquisition to prevent deadlock

10. Scenario: Reverse Words in a Sentence

Problem:
In a voice-to-text application, sentences are generated in reverse order by mistake. Write a program to
reverse the words in a sentence to correct the transcript.

Input:
"world the to Welcome"
Expected Output:
"Welcome to the world"

11. Scenario (OOPs – Inheritance): Employee Management System

You are designing a software for a company. The system should manage different types of employees –
regular employees and managers. Managers have an additional bonus field. Use inheritance to
calculate and display total salary.

Input:
Employee: name = “John”, salary = 30000
Manager: name = “Alice”, salary = 50000, bonus = 10000

Expected Output:

John - Total Salary: 30000


Alice - Total Salary: 60000

12. Scenario (OOPs – Encapsulation): Bank Account

You are implementing a class BankAccount where balance and account number must be secure
(private). Allow the user to deposit, withdraw, and check balance through public methods only.
Input:
Deposit: 1000
Withdraw: 400

Expected Output:

Balance after deposit: 1000


Balance after withdrawal: 600

13. Scenario (OOPs – Polymorphism): Shape Area Calculator

Develop a program with a base class Shape and derived classes Circle, Rectangle, and Triangle. Each
class must have an area() method. Use polymorphism to call the appropriate method at runtime.

Input:
Circle: radius = 3
Rectangle: length = 4, width = 5
Triangle: base = 6, height = 3

Expected Output:

Circle Area: 28.27


Rectangle Area: 20
Triangle Area: 9

14. Scenario (Linked List): Add Two Numbers Represented by Linked Lists

You are building a calculator for large numbers stored as linked lists (digits in reverse). Write a function
to add two numbers and return the result as a linked list.

Input:
List1 = 2 → 4 → 3 (represents 342)
List2 = 5 → 6 → 4 (represents 465)

Expected Output:
7 → 0 → 8 (represents 807)

15. Scenario (Linked List): Remove N-th Node from End

In an audio processing pipeline, you store filters as a linked list. To optimize the filter chain, you want
to remove the N-th filter from the end.

Input:
List = 1 → 2 → 3 → 4 → 5, n = 2

Expected Output:
1→2→3→5
16. Scenario (Stack): Valid Parentheses Checker

While developing a compiler, you need to verify that every opening bracket in code has a matching
closing bracket using a stack.

Input:
"{[()]}"

Expected Output:
Valid

17. Scenario (Queue): First Non-Repeating Character in a Stream

In a live typing assistant, you are given a stream of characters. After each character, show the first
character that has not repeated so far.

Input:
aabc

Expected Output:
a#bb

18. Scenario (Sorting): Arrange Students by Marks

You are tasked with building a gradebook where students must be listed in descending order of marks.
Implement a sorting algorithm (e.g., merge sort or quick sort).

Input:
[{name: "Amit", marks: 75}, {name: "Rita", marks: 89}, {name: "John", marks: 65}]

Expected Output:
Rita (89), Amit (75), John (65)

19. Scenario (Searching – Binary Search): Find a Product by ID

In an e-commerce inventory system, product IDs are sorted. Implement a binary search to quickly
locate if a product ID exists.

Input:
Product IDs = [1001, 1003, 1005, 1010], target = 1005

Expected Output:
Product Found at Index: 2

20. Scenario (Searching): Find First and Last Position of Element


In a testing system, student scores are stored in a sorted array. Write a program to find the first and
last occurrence of a specific score.

Input:
[5, 7, 7, 8, 8, 10], score = 8

Expected Output:
First Index = 3, Last Index = 4

21. Scenario (OOPs – Constructor Overloading): Student Registration System

You are developing a student registration system. Sometimes students register with only a name;
other times with a name and age. Use constructor overloading to handle both scenarios.

Input:

Student s1("Amit");
Student s2("Rita", 21);

Expected Output:

Student: Amit, Age: N/A


Student: Rita, Age: 21

22. Scenario (OOPs – Abstraction): Online Payment System

Design an abstract class Payment with a method pay(amount). Derive classes like CreditCard and
PayPal which implement pay() in their own way.

Input:

Payment *p1 = new CreditCard();


p1->pay(500);

Expected Output:

Paid ₹500 via Credit Card.

23. Scenario (Linked List): Reverse Nodes in K-Group

You’re building a photo album where each k photos should be rearranged in reverse to form a design
pattern. Implement a function to reverse every group of k nodes in a linked list.

Input:
1 → 2 → 3 → 4 → 5, k = 2

Expected Output:
2→1→4→3→5
24. Scenario (Linked List): Merge K Sorted Lists

You need to combine several sorted mailing lists. Implement a program to merge k sorted linked lists
into one sorted linked list.

Input:
[1→4→5], [1→3→4], [2→6]

Expected Output:
1→1→2→3→4→4→5→6

25. Scenario (Stack): Evaluate Reverse Polish Notation

In a calculator app, you want to implement postfix (RPN) evaluation using a stack. Each operator
applies to the last two numbers.

Input:
["2", "1", "+", "3", "*"]

Expected Output:
9 (as (2 + 1) * 3 = 9)

26. Scenario (Sorting – Bubble Sort Visualization): Animation Tool

In an educational animation tool, you want to show how bubble sort works step by step on a list of
numbers.

Input:
[5, 3, 8, 4]

Expected Output:

Step 1: [3, 5, 8, 4]
Step 2: [3, 5, 4, 8]
Step 3: [3, 4, 5, 8]

27. Scenario (Searching – Linear Search): Contact List Search

In a contact list app, a user can search by name. Use linear search to find the index of a contact.

Input:
["Arjun", "Deepa", "Meena"], search = “Meena”

Expected Output:
Contact found at index: 2
28. Scenario (Sorting – Insertion Sort): Sort Attendance by Roll Number

You are developing a school attendance system. Students arrive randomly and you want to sort them
by roll number using insertion sort.

Input:
[45, 12, 89, 33]

Expected Output:
[12, 33, 45, 89]

29. Scenario (OOPs – Static Members): Track Object Count


Implement a class Book with a static variable that tracks how many book objects have been created.

Input:
Book b1, b2, b3;
Expected Output:
Total Books Created: 3

30. Scenario (Linked List): Detect and Remove Loop


In a navigation system, a wrong loop can crash the program. Write a function to detect and remove the
loop from a linked list.

Input:
1 → 2 → 3 → 4 → 2 (cycle)
Expected Output:
Loop detected and removed.

31. Scenario (Linked List): Check Palindrome


A word is stored as a singly linked list. Write a function to check if the word is a palindrome.

Input:
r→a→d→a→r
Expected Output:
True

32. Scenario (Linked List): Sort a Linked List


You're managing product prices stored in a linked list. Write a function to sort the list.

Input:
10 → 3 → 7 → 1
Expected Output:
1 → 3 → 7 → 10
33. Scenario (Stack): Infix to Postfix Conversion
Implement a feature in a compiler that converts an infix expression to postfix using a stack.

Input:
(A + B) * C
Expected Output:
AB+C*

34. Scenario (Stack): Remove Adjacent Duplicates


In a data compression system, you want to remove adjacent duplicates from a string using a stack.

Input:
"abbaca"
Expected Output:
"ca"

35. Scenario (Stack): Next Greater Element


In a stock analysis tool, return the next greater element for each number using a stack.

Input:
[2, 1, 2, 4, 3]
Expected Output:
[4, 2, 4, -1, -1]

36. Scenario (Sorting – Selection Sort): Sort Exam Scores


A teacher wants to manually sort scores using selection sort.

Input:
[40, 20, 60, 10]
Expected Output:
[10, 20, 40, 60]

37. Scenario (Sorting – QuickSort): Organize Books by ID


Books stored in an array must be sorted using QuickSort.

Input:
[34, 7, 23, 32]
Expected Output:
[7, 23, 32, 34]
38. Scenario (Searching – Ternary Search): Game Level Finder
You need to search a score in a sorted leader-board using ternary search.

Input:
[10, 20, 30, 40, 50], search = 40
Expected Output:
Found at index: 3

39. Scenario (Searching – Exponential Search): Find a Customer ID


In a large, sorted database, use exponential search to find a customer ID.

Input:
[1, 3, 5, 7, 9, 15, 20, 30], target = 15
Expected Output:
Found at index: 5

40. Scenario (OOPs – Copy Constructor): Copy Product Info


You clone a product entry using a copy constructor.

Input:
Product A with id=101, name="Laptop"
Product B = copy of A
Expected Output:
Product B: id=101, name=Laptop

41. Scenario (Queue – Priority Queue): Hospital Emergency Queue


Patients are prioritized by severity. Use a priority queue to serve critical ones first.

Input:
[(name="A", priority=2), (name="B", priority=1)]
Expected Output:
B is served before A

42. Scenario (Sorting – Counting Sort): Sort Exam Grades (0-100)


Use counting sort to efficiently sort exam scores that range from 0 to 100.

Input:
[50, 20, 100, 75, 20]
Expected Output:
[20, 20, 50, 75, 100]

43. Scenario (Linked List – Intersection Point): Merge Users' Activity


Two activity logs (linked lists) merge at a common point. Find where they intersect.
Input:
List A: 1 → 2 → 3 → 6 → 7
List B: 4 → 5 → 6 → 7
Expected Output:
Intersection at node with value: 6

44. Scenario (Queue – Circular Buffer): IoT Sensor Buffer


Sensor data is stored in a fixed-size circular queue. Handle enqueue and dequeue operations.

Input:
Enqueue 3, 4, 5 → Dequeue → Enqueue 6
Expected Output:
Queue = [4, 5, 6]

45. Scenario (Sorting – Shell Sort): Optimize Sort with Gap


Implement shell sort to reduce number of comparisons for partially sorted data.

Input:
[10, 8, 9, 2, 4]
Expected Output:
[2, 4, 8, 9, 10]

46. Scenario (Linked List – Remove Duplicates from Unsorted List)


You’re given an unsorted linked list with duplicates. Remove duplicates.

Input:
10 → 20 → 10 → 30 → 20
Expected Output:
10 → 20 → 30

47. Scenario (Stack – Balanced Brackets)


You want to validate if a string with {[()]} is balanced.

Input:
"{[()]}"
Expected Output:
Balanced

48. Scenario (Queue – Implement Using Array)


Create a queue using an array with enqueue and dequeue.

Input:
Enqueue: 1, 2 → Dequeue → Enqueue: 3
Expected Output:
Queue = [2, 3]

49. Scenario (Sorting – Radix Sort): Sort Phone Numbers

Sort a list of 10-digit phone numbers using radix sort.

Input:
[9876543210, 9123456789, 9988776655]
Expected Output:
[9123456789, 9876543210, 9988776655]

50. Scenario (2D Array – Pathfinding Simulation): Fire Escape Plan in a Building

You are simulating an emergency fire escape plan in a building represented by a 2D grid. Each cell in
the grid can be:

 'S' = start position (person)


 'E' = exit
 '1' = wall (cannot pass)
 '0' = open path

Your goal is to write a program to find the shortest path from 'S' to 'E' using Breadth-First Search (BFS)
or another suitable algorithm. If there is no path, return -1.

Input (Grid):

44

[
['S', '0', '1', '0'],
['1', '0', '1', '0'],
['0', '0', '0', '0'],
['1', '1', '1', 'E']
]

Expected Output:

Shortest path length: 7

The path is:


(0,0) → (0,1) → (1,1) → (2,1) → (2,2) → (2,3) → (3,3)

You might also like