C Programming with DSA Interview Questions in Delhi
36 practice questions with answers for C Programming with DSA interviews in Delhi.
C Programming with DSA jobs in Delhi
Delhi NCR has one of India's biggest pools of IT, consulting, banking and start-up jobs. Delhi itself hosts many corporate, government-tech and consulting offices, and most candidates also apply across Noida and Gurgaon, so interviews here mix service-company and product-company styles.
Below are 36 questions that match the mix of service, product and domain employers hiring c developers in Delhi.
Solved for DelhiStart practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
✓ 3 questions free • Unlock the rest in seconds
01
An interview asks for the minimum number of coins to make an amount. How do you approach it?
Greedy fails for some coin sets, such as coins 1, 3, 4 with amount 6, where greedy gives three coins but two coins of 3 is optimal. Use DP: dp[0] = 0 and dp[x] = 1 + min over coins c of dp[x - c], filling from 1 to the amount. Time is O(amount times coins) and space O(amount). Report -1 if the amount cannot be formed.
02
Why are self-balancing trees like AVL and red-black trees needed?
A plain BST can degrade to a linked list with O(n) operations when data arrives in sorted order. AVL trees keep the height difference of subtrees at most one using rotations, giving faster lookups. Red-black trees use colour rules with looser balance, so inserts and deletes need fewer rotations. Both guarantee O(log n). Red-black trees are used in the Linux kernel, C++ std::map and Java TreeMap.
Bit fields let struct members use a specified number of bits, such as unsigned int ready : 1; unsigned int mode : 3;, which saves memory for flags. They are common in embedded code and protocol headers. However, bit ordering, padding and whether plain int bit fields are signed are implementation defined, so for portable hardware register or wire format access, explicit masks and shifts are safer.
04
What is the difference between an array and a pointer?
An array is a block of contiguous elements whose size is fixed and known to the compiler; sizeof gives the full array size. A pointer is a variable holding an address; sizeof gives the pointer size. An array name decays to a pointer to its first element in most expressions, but it cannot be reassigned. When passed to a function, an array always becomes a pointer, losing its length.
Track the best sum ending here and the overall best.
long maxSubarray(const int *a, int n) {
long cur = a[0], best = a[0];
for (int i = 1; i < n; i++) {
cur = (cur + a[i] > a[i]) ? cur + a[i] : a[i];
if (cur > best) best = cur;
}
return best;
}
Input {-2, 1, -3, 4, -1, 2, 1, -5, 4} returns 6 for subarray 4, -1, 2, 1.
Sliding window solves problems on contiguous subarrays or substrings by keeping a window with two indexes and moving them forward instead of rechecking every subarray. A fixed window finds things like the maximum sum of k elements, while a variable window expands and shrinks, as in the longest substring without repeating characters. It turns O(n squared) brute force into O(n).
07
How do you set, clear and toggle a particular bit in C?
Use bit masks with shift operators.
x |= (1u << n); // set bit n
x &= ~(1u << n); // clear bit n
x ^= (1u << n); // toggle bit n
int bit = (x >> n) & 1u; // read bit n
Use unsigned types so shifts are well defined. These operations are common in embedded code for configuring hardware registers.
Use a slow pointer moving one step and a fast pointer moving two steps. If the list has a cycle, the fast pointer eventually meets the slow one inside the loop; if fast reaches NULL, there is no cycle. To find the cycle start, reset one pointer to head and move both one step at a time; they meet at the start. It uses O(n) time and O(1) space.
09
What is a trie and when is it better than a hash table?
A trie is a tree where each edge represents a character, so words sharing a prefix share a path. Lookup and insert take O(L) for a word of length L, independent of how many words are stored. It beats a hash table for prefix queries such as autocomplete, spell checking and longest prefix matching in IP routing. The trade-off is higher memory use from many child pointers.
10
What is the difference between break and continue in C?
break immediately exits the nearest enclosing loop or switch statement, and execution continues after it. continue skips the rest of the current loop iteration and moves to the next one; in a for loop the update expression still runs. In nested loops both affect only the innermost loop, so a flag or goto is needed to exit outer loops early.
11
What is the difference between a macro and an inline function?
A macro is plain text substitution by the preprocessor, with no type checking, and arguments may be evaluated more than once, so SQUARE(i++) misbehaves. An inline function is a real function with type checks and single evaluation of arguments, which the compiler may expand in place for speed. Prefer static inline functions and use macros only for things like conditional compilation.
12
Tell me about a time you chose the right data structure under pressure.
Situation: during a hackathon our C route planner was too slow to answer queries live. Task: fix it within a few hours. Action: I profiled it, found repeated linear searches of a list of stops and replaced them with a hash table keyed by stop id, plus a queue for BFS. Result: queries went from 4 seconds to 30 ms and we won second place.
13
Why is a dummy or sentinel node useful in linked list code?
A dummy node placed before the real head removes special cases for an empty list or for inserting and deleting at the head, because every real node then has a previous node. Code for merging lists, removing elements and partitioning becomes shorter and less error prone. At the end, return dummy.next as the new head. It costs one extra node.
14
A program prints garbage values for a local variable. What is the likely cause?
Local automatic variables are not initialised in C, so they hold whatever bytes were on the stack. Reading them is undefined behaviour and gives random results. Initialise every variable at declaration, such as int sum = 0;. Compiling with -Wall -Wuninitialized and running under Valgrind or with -fsanitize=memory helps detect such reads early.
15
Write binary search in C that returns the index of the target or -1.
Use an overflow safe midpoint.
int binarySearch(const int *a, int n, int target) {
int lo = 0, hi = n - 1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (a[mid] == target) return mid;
if (a[mid] < target) lo = mid + 1;
else hi = mid - 1;
}
return -1;
}
Time O(log n). The array must be sorted in ascending order.
16
Your stack implementation crashes with deep recursion converted to an explicit stack. What would you check?
Check for stack overflow of your own array: push must verify top < capacity and either fail or grow the array with realloc. Check pop on an empty stack returns an error instead of reading index -1. If using realloc, make sure no pointers into the old buffer are kept. Add asserts in debug builds and test with the largest expected input.
17
A program that writes logs with fprintf loses the last lines when it crashes. Why, and how do you fix it?
stdio streams are buffered, so fprintf stores data in memory and writes it to disk only when the buffer fills, the file closes or fflush is called. A crash loses whatever is still in the buffer. Call fflush after important log lines, set line buffering with setvbuf(fp, NULL, _IOLBF, 0) or write critical messages to unbuffered stderr. For durability on disk, add fsync on POSIX systems.
18
Write BFS on a graph stored as an adjacency matrix.
Use a queue and a visited array.
void bfs(int n, int adj[n][n], int start) {
int visited[n], queue[n], front = 0, rear = 0;
for (int i = 0; i < n; i++) visited[i] = 0;
visited[start] = 1;
queue[rear++] = start;
while (front < rear) {
int u = queue[front++];
printf("%d ", u);
for (int v = 0; v < n; v++) {
if (adj[u][v] && !visited[v]) {
visited[v] = 1;
queue[rear++] = v;
}
}
}
}
19
Which gcc flags would you use to build and debug a C program safely?
A good development build is:
gcc -std=c17 -Wall -Wextra -Wpedantic -g -O1 \
-fsanitize=address,undefined \
-o app main.c utils.c
-Wall and -Wextra turn on useful warnings, -g adds debug symbols for gdb, and sanitizers catch memory errors and undefined behaviour at runtime. For release, drop sanitizers and use -O2.
20
What is structure padding and how can you reduce it?
The compiler inserts padding bytes between members so each one is aligned, which can make a struct larger than the sum of its members. struct { char a; int b; char c; } is usually 12 bytes instead of 6. Reduce padding by ordering members from largest to smallest alignment. Packing with __attribute__((packed)) removes padding but can slow access or fault on some CPUs.
volatile tells the compiler that a variable can change outside normal program flow, for example a hardware register, a variable changed in an interrupt handler or memory shared with another device. The compiler must read it from memory every time and cannot cache it in a register or remove repeated reads. It does not provide atomicity or thread safety on its own.
C stores multidimensional arrays in row-major order: all elements of row 0, then row 1 and so on, in one contiguous block. Element a[i][j] of an array with C columns is at offset i * C + j. Traversing row by row is cache friendly and much faster than column by column for large matrices. When passing a 2D array to a function, every dimension except the first must be specified.
23
What is the difference between char s[] = "hello" and char *s = "hello"?
char s[] = "hello" creates a modifiable array of 6 bytes, usually on the stack, initialised with a copy of the literal. char *s = "hello" makes a pointer to a string literal stored in read-only memory; modifying it is undefined behaviour and often crashes. Declare such pointers as const char * so the compiler catches accidental writes.
In expressions, types smaller than int, like char and short, are promoted to int before arithmetic. In mixed signed and unsigned comparisons, the signed value may convert to unsigned. So if (-1 < sizeof(int)) is false, because -1 becomes a huge unsigned number. These rules cause subtle bugs in embedded and systems code, so compile with -Wall -Wextra and use explicit casts carefully.
25
What is the difference between strcpy, strncpy and snprintf for copying strings?
strcpy copies until the null terminator with no bounds check, so it can overflow. strncpy limits the count but does not add a terminator if the source is too long and pads with zeros otherwise, which surprises many developers. snprintf(dst, size, "%s", src) always terminates and returns the length it wanted, so you can detect truncation. Prefer snprintf or a checked helper.
26
Tell me about a time you optimised an algorithm in a real project.
Situation: a C tool comparing two inventory files of 5 lakh rows took 25 minutes. Task: make it run in a nightly window of 2 minutes. Action: I found nested loops doing O(n squared) matching, sorted both files with qsort and merged them with two pointers, which is O(n log n). Result: runtime fell to 40 seconds, and the approach became our standard for file reconciliation jobs.
27
A function to insert at the head does not change the list in main. Why?
C passes arguments by value, so the function receives a copy of the head pointer; changing that copy does not affect main. Pass a pointer to the head, as in void push(Node **head, int x), and assign *head = newNode, or return the new head and assign it in the caller with head = push(head, x). This is a very common fresher interview mistake.
A memory leak happens when dynamically allocated memory is never freed and the last pointer to it is lost, so the program keeps growing in memory use. Long running services and embedded systems eventually fail. Detect leaks with Valgrind memcheck, AddressSanitizer with LeakSanitizer or allocation tracking wrappers. Prevent them with clear ownership rules and a single cleanup path per function.
29
Write a C program that counts lines, words and characters in a file.
Read character by character with fgetc.
FILE *fp = fopen(path, "r");
if (!fp) { perror("fopen"); return 1; }
long lines = 0, words = 0, chars = 0;
int c, inWord = 0;
while ((c = fgetc(fp)) != EOF) {
chars++;
if (c == '\n') lines++;
if (isspace(c)) inWord = 0;
else if (!inWord) { inWord = 1; words++; }
}
fclose(fp);
printf("%ld %ld %ld\n", lines, words, chars);
c is int so EOF can be distinguished from valid bytes.
Situation: a C based telemetry agent grew by 200 MB a day on customer servers. Task: find and fix the leak quickly. Action: I reproduced it with recorded traffic under Valgrind and found that an error path returned early without freeing a parsed message buffer. I restructured the function with a single cleanup label and added a leak check job to CI. Result: memory stayed flat for weeks after the patch.
31
Use a tagged union to store either an int, a float or a string value.
realloc may move the block and returns the new address, so old pointers to the block become invalid. Writing ptr = realloc(ptr, n) also leaks the original memory if realloc fails and returns NULL. Store the result in a temporary pointer, check for NULL, then assign. Make sure no other pointers still refer to the old location after a successful move.
33
Remove the nth node from the end of a linked list in one pass.
Move a lead pointer n steps ahead, then move both together.
Node *removeNthFromEnd(Node *head, int n) {
Node dummy = {0, head};
Node *fast = &dummy, *slow = &dummy;
for (int i = 0; i <= n; i++) fast = fast->next;
while (fast) { fast = fast->next; slow = slow->next; }
Node *del = slow->next;
slow->next = del->next;
free(del);
return dummy.next;
}
The dummy node handles removing the head.
34
What is a heap and how does it implement a priority queue?
A binary heap is a complete binary tree stored in an array where every parent is smaller than its children for a min heap, or larger for a max heap. For index i, children are at 2i + 1 and 2i + 2. Insert adds at the end and sifts up, and extracting the top swaps it with the last element and sifts down, both O(log n). Building a heap from an array takes O(n).
A topological sort orders the vertices of a directed acyclic graph so every edge goes from earlier to later. Kahn's algorithm repeatedly removes vertices with zero in-degree using a queue; DFS adds vertices to the order after finishing their descendants. If not all vertices are processed, the graph has a cycle. It is used for build systems, course prerequisites and task scheduling.
36
Insert a node at the end of a singly linked list using a double pointer.
A pointer to pointer handles the empty list without special cases.
int append(Node **head, int value) {
Node *n = malloc(sizeof *n);
if (!n) return -1;
n->data = value;
n->next = NULL;
while (*head) head = &(*head)->next;
*head = n;
return 0;
}
Call it as append(&head, 5). Keep a tail pointer if you append often.
Which companies hire C Programming with DSA professionals in Delhi?
Companies with large offices in Delhi include Samsung. Use their company pages below to practise employer-specific sets.
Are C Programming with DSA interviews in Delhi different from other cities?
The questions depend more on the company than the city. Delhi's mix of employers decides the style: Delhi itself hosts many corporate, government-tech and consulting offices, and most candidates also apply across Noida and Gurgaon, so interviews here mix service-company and product-company styles
How do I find C Programming with DSA jobs in Delhi?
Shortlist companies with Delhi offices, keep your CV focused on C Programming with DSA projects, apply on company career pages and job portals with the Delhi filter, and practise the questions on this page before each interview.