Q. Delete a node in a Binary Search Tree
asked 2xmediumTreesTechnical2017-2023
Ans. Delete by searching for the key, then handle three cases: leaf, one child, or two children. A leaf is removed directly, and a node with one child is replaced by that child. For two children, replace its value with the inorder successor or predecessor, then delete that replacement node. Time is O(h), space O(h) recursively.
Q. Detect and remove a loop in a linked list
asked 2xmediumLinked listsManagerial, Technical2017-2023
Ans. Use Floyd’s slow and fast pointer method to detect the loop, then remove it by finding the node where the cycle starts and setting the previous node’s next pointer to null. After slow and fast meet, move one pointer to head and advance both one step at a time. Time is O(n), space is O(1).
Q. Design the recursion tree to generate the power set of a given input string.
asked 2xmediumBacktrackingTechnical2023
Ans. Use a binary recursion tree where each level represents one character, with two branches: exclude the character or include it in the current subset. Start at index 0 with an empty current string. When the index reaches the input length, output the current subset. This generates 2^n subsets, with O(n) recursion depth.
Q. What are magical (dunder) methods in Python? Explain with an example using generators.
asked 2xmediumOOPTechnical2023
Ans. Magical or dunder methods are special Python methods with double underscores, such as __iter__ and __next__, that let objects work with built-in language features. A generator uses these iterator methods automatically: calling iter on it returns itself, and each next call resumes execution until yielding a value or raising StopIteration.
Q. Explain microservice architecture, decoupling mechanisms, and the role of messaging queues.
asked 2xmediumMicroservicesTechnical2023
Ans. Microservice architecture splits a system into small, independently deployable services, each owning a specific business capability and usually its own data. Decoupling comes from clear APIs, separate databases, contracts, events, and independent scaling. Messaging queues add asynchronous communication, buffering, retries, and failure isolation, so services do not need to be available at the same time.
Q. Check whether a given string is a palindrome
asked 2xeasyStringsTechnical2017-2019
Ans. Use two pointers, one at the start of the string and one at the end, and compare characters while moving inward. If any pair differs, it is not a palindrome; if the pointers meet or cross, it is. This uses no extra data structure and runs in O(n) time with O(1) space.
Q. What are in-built language exceptions and how can you raise custom exceptions?
asked 2xeasyProgrammingTechnical2023
Ans. In-built language exceptions are predefined error types provided by a language, such as null reference, type, index, value, file, or arithmetic errors. They are raised automatically by the runtime or manually when appropriate. Custom exceptions are raised by defining a new exception class, usually extending the base exception type, then throwing or raising it.
Q. Explain Kadane's Algorithm.
asked 1xmediumArraysTechnical2018
Ans. Kadane’s Algorithm finds the maximum sum of a contiguous subarray in linear time. It scans the array while keeping the best sum ending at the current position and the best sum seen overall. At each element, either extend the previous subarray or start a new one. It runs in O(n) time and O(1) space.
Q. Find the Kth maximum element in an array
asked 1xmediumArraysTechnical2017
Ans. Use a min-heap of size K to find the Kth maximum element. Insert elements until the heap has K items, then for each remaining element, replace the heap root if the element is larger. The root is then the answer. This takes O(n log K) time and O(K) space.
Q. Check whether a binary tree is a BST or not
asked 1xmediumTreesTechnical2015
Ans. Use a depth first traversal with valid lower and upper bounds for each node. A node is valid only if its value lies strictly between those bounds, then update the bounds for its left and right children. This checks the whole tree in O(n) time and O(h) recursion space.
Q. Generate all permutations of a given string.
asked 1xmediumStringsTechnical2016
Ans. Use backtracking to build permutations one character at a time until the current string has the same length as the input. Keep a used boolean array to mark chosen characters, or swap characters in place. The key detail is duplicates: sort first and skip repeated unused choices. Time complexity is O(n! × n).
Q. Merge two sorted singly linked lists in-place
asked 1xmediumLinked listsTechnical2017
Ans. Use two pointers to compare the current nodes of both lists, repeatedly link the smaller node to the result, and advance that list’s pointer. Keep a tail pointer for the merged list and attach the remaining nodes when one list ends. This relinks existing nodes, so time is O(n + m) and space is O(1).
Q. Explain semaphore programming and its use cases
asked 1xmediumOperating systemsTechnical2016
Ans. Semaphore programming uses an integer synchronisation primitive to control access to shared resources among concurrent threads or processes. A wait operation decrements or blocks when unavailable, and a signal operation increments and wakes a waiter. Common use cases include mutual exclusion, limiting connection pools, producer consumer queues, and ordering events.
Q. Merge K sorted arrays using an efficient approach
asked 1xmediumArraysTechnical2023
Ans. Use a min-heap to merge the K sorted arrays efficiently. Insert the first element of each array with its array index and element index, repeatedly extract the smallest element, and insert the next element from the same array. For total N elements, time complexity is O(N log K) and space is O(K).
Q. Declare and explain complex function pointers in C
asked 1xmediumOOPTechnical2016
Ans. A complex function pointer in C declares a variable that stores the address of a function, including its return type and parameter types. Read it from the name outward, using parentheses to bind the pointer before the function call part. For very complex cases, use typedefs to name intermediate function pointer types and improve readability.
Q. Given a string, return all palindromic substrings.
asked 1xmediumStringsTechnical2019
Ans. Use centre expansion: for each index, expand outwards for odd length palindromes, and between this index and the next for even length palindromes. Each time the characters match, add that substring to a result list. This returns palindromic occurrences, including duplicates by position. Time is O(n²), plus output storage.
Q. Given a character array of size 20, set the 102nd bit
asked 1xmediumBit manipulationTechnical2015
Ans. Set byte 12, bit 6: OR the 13th character with a mask of 1 shifted left by 6. A char array of 20 holds 160 bits, assuming 8-bit chars. If the 102nd bit is counted from 1 instead of 0, use byte 12, bit 5.
Q. Delete all nodes in a linked list which occur more than twice
asked 1xmediumLinked listsTechnical2017
Ans. Count frequencies of each value, then remove every node whose value appears more than twice. Use a hash map in the first pass to store counts, then traverse again with a dummy head to relink only allowed nodes. This handles head deletion cleanly and runs in O(n) time with O(n) extra space.
Q. Find the largest sum contiguous subarray (Kadane’s Algorithm)
asked 1xmediumArraysTechnical2015
Ans. Use Kadane’s algorithm by scanning the array once, keeping the best subarray sum ending at the current index and the best sum seen so far. At each element, either extend the previous subarray or start a new one. It uses only a few variables, so the time complexity is O(n) and space is O(1).
Q. Perform level order traversal of a binary tree in spiral form.
asked 1xmediumTreesTechnical2018
Ans. Use two stacks to traverse the tree level by level while alternating direction. Push the root into one stack, then process nodes from the current stack and push their children into the other stack in left-right or right-left order depending on the level. Swap stacks after each level. Time is O(n), space is O(n).
Q. Given an array, find all elements that occur odd number of times
asked 1xmediumArraysTechnical2017
Ans. Use a frequency map: scan the array, count each element, then return the elements whose counts are odd. This works for any number of odd-occurring values and any element type that can be used as a key. The time complexity is O(n), and the extra space is O(k), where k is distinct elements.
Q. Differentiate between user-level threads and kernel-level threads
asked 1xmediumOperating systemsTechnical2016
Ans. User-level threads are managed by a user-space library, while kernel-level threads are managed and scheduled by the operating system kernel. User threads are faster to create and switch but one blocking system call can block the whole process. Kernel threads cost more but can run truly in parallel on multiple CPUs.
Q. Explain Trie data structure, its node structure and implementation
asked 1xmediumTreesTechnical2017
Ans. A Trie is a tree used to store strings by sharing common prefixes, so each path from root represents a word or prefix. Each node usually contains links to child nodes, often by character, and a flag marking end of word. Insert and search process characters one by one, taking O(L) time for string length L.
Q. Explain data modeling concepts and the basics of a CI/CD pipeline.
asked 1xmediumDBMSTechnical2023
Ans. Data modelling defines how data is structured, related, constrained and stored, while a CI/CD pipeline automates building, testing and deploying software changes. Key data modelling concepts include entities, attributes, relationships, keys, normalisation and schemas. A basic pipeline runs on each commit, builds the code, runs tests, packages the artefact and deploys safely.
Q. How can a class object be used as a key in a dictionary in Python?
asked 1xmediumOOPTechnical2023
Ans. A class instance can be used as a dictionary key if it is hashable. By default, user-defined objects are hashable by identity, so each instance can be a distinct key. If the class defines equality with __eq__, it should also define a consistent __hash__, and the fields used for hashing should not change.
Q. Find the minimum number of perfect squares that sum to a given number
asked 1xmediumDynamic programmingManagerial2023
Ans. Use dynamic programming where dp[i] is the minimum number of perfect squares needed to sum to i. Initialise dp[0] to 0, then for each i from 1 to n, try every square j*j not greater than i and update dp[i] from dp[i - j*j] + 1. This takes O(n√n) time and O(n) space.
Q. How do data types affect memory allocation in a programming language?
asked 1xmediumOperating systemsTechnical2023
Ans. Data types affect memory allocation by telling the language how much space a value needs and how that space should be interpreted. For example, an integer, character, float, or object may require different amounts of memory. The key detail is that fixed-size types are usually allocated predictably, while dynamic types may need extra memory and runtime management.
Q. Perform level order traversal of a binary tree without using recursion
asked 1xmediumTreesTechnical2017
Ans. Use an iterative breadth first search with a queue. Put the root in the queue, then repeatedly remove the front node, visit it, and add its left and right children if they exist. This processes nodes level by level. The time complexity is O(n), and the space complexity is O(w), where w is the maximum width.
Q. Search an element in a matrix where each row and each column is sorted
asked 1xmediumArraysTechnical2016
Ans. Start at the top right element and eliminate one row or one column at each step. If the current value is the target, return found. If it is greater, move left. If it is smaller, move down. This works because rows and columns are sorted. Time is O(rows + columns), space is O(1).
Q. Explain the Linear Regression model and how data is fitted to the model
asked 1xmediumMachine learningTechnical2017
Ans. Linear regression models the relationship between input features and a continuous target as a straight line or linear combination of features. The model is fitted by choosing coefficients that minimise the error between predicted and actual values, usually using least squares. In practice this is done analytically or with gradient descent.
Q. Perform level order traversal of a binary tree in spiral (zigzag) order
asked 1xmediumTreesTechnical2015
Ans. Traverse the tree level by level, alternating the direction of output at each level. Use a queue to process nodes in breadth-first order, record all nodes of the current level, then reverse that level when needed. Toggle the direction after each level. Time complexity is O(n), and extra space is O(w), where w is tree width.
Q. What steps would you take for code approval in a production environment?
asked 1xmediumProcessManagerial2023
Ans. Choose a situation where you moved code safely through review, testing, and release. Emphasise raising a pull request, linking requirements, ensuring automated tests pass, checking security and rollback plans, getting peer or senior approval, and following change control. Interviewers listen for ownership, risk awareness, communication, and respect for production stability.
Q. Write code that returns true if one matrix is a subset of another matrix
asked 1xmediumArraysHR2016
Ans. Use a frequency hash map of the larger matrix and check every value in the smaller matrix against it. Count each element in the larger matrix, then for each element in the candidate subset, fail if the count is missing or zero, otherwise decrement it. This handles duplicates correctly. Time complexity is O(mn + pq), with O(mn) space.
Q. Traverse a binary tree in an anticlockwise direction (boundary traversal)
asked 1xmediumTreesTechnical2023
Ans. Traverse root, left boundary, all leaves, then right boundary in reverse order. Exclude leaves from the left and right boundary steps to avoid duplicates. Use recursion or a stack for leaves, and a temporary stack/list for the right boundary reversal. Time complexity is O(n), with O(h) auxiliary space excluding output.
Q. Find the first non-repeating character in a given string (optimized solution)
asked 1xmediumStringsTechnical2015
Ans. Use a hash map to count each character, then scan the string again and return the first character whose count is one. This preserves the original order while keeping lookup constant time. The time complexity is O(n), and the extra space is O(k), where k is the number of distinct characters.
Q. Find the kth element from the end of a singly linked list using a single pass
asked 1xmediumLinked listsTechnical2017
Ans. Use two pointers: move the first pointer k nodes ahead, then move both pointers together until the first reaches the end. The second pointer is then at the kth node from the end. This uses no extra data structure, runs in O(n) time, and O(1) space. If k is too large, return null or an error.
Q. Write a function to return the length of a string without using any variables
asked 1xmediumStringsTechnical2015
Ans. Use recursion: if the current character is the string terminator, return 0; otherwise return 1 plus the length of the remaining string. The call stack replaces explicit variables. This needs no extra data structure, but uses recursive stack space. Time complexity is O(n) and space complexity is O(n).
Q. Explain stack segment, heap segment, and read-only memory segments in a process
asked 1xmediumOperating systemsTechnical2016
Ans. The stack stores function call frames and local automatic variables, the heap stores dynamically allocated objects, and read-only segments store immutable program data such as machine code and string constants. The stack is managed automatically and grows or shrinks with calls, the heap is managed by an allocator or GC, and read-only pages are protected from writes.
Q. Did you ever encounter a person who was hard to handle? How did you handle them?
asked 1xmediumConflict resolutionHR2018
Ans. Choose a work situation where the difficulty affected delivery, not a personal complaint. Emphasise that you stayed calm, listened, set clear expectations, and focused on facts and shared goals. Interviewers listen for self-control, empathy, boundaries, and whether you resolved the issue professionally without blaming or escalating unnecessarily.
Q. How do data types affect memory allocation in programming languages like Python?
asked 1xmediumOperating systemsTechnical2023
Ans. Data types determine how much memory a value needs and how the runtime stores, references, and manages it. In Python, every value is an object with overhead for type and reference count, so an int uses more memory than raw machine integer. Containers like lists store references to objects, not the objects directly.
Q. Evaluate outputs of sizeof and strlen expressions on empty string and NULL pointer
asked 1xmediumCTechnical2015
Ans. For an empty string literal, sizeof("") is 1 and strlen("") is 0. The size includes the terminating null character, while strlen counts characters before it. For a NULL pointer, sizeof(pointer) gives the pointer size, typically 4 or 8 bytes, but strlen(NULL) is undefined behaviour and may crash.
Q. Store a list of names of unknown length dynamically in contiguous memory locations
asked 1xmediumMemory managementTechnical2016
Ans. Use a dynamic array, such as a vector or ArrayList, to store the names in contiguous memory. In C, this would usually be a resizable array of char pointers allocated with malloc and grown with realloc. When capacity is full, allocate more space. Access is O(1), and append is amortised O(1).
Q. Explain Breadth First Search (BFS), write its code, and give real-time applications
asked 1xmediumGraphsTechnical2015
Ans. Breadth First Search visits a graph level by level from a start node, using a queue to process nearest nodes first. Mark the start visited, enqueue it, then repeatedly dequeue a node and enqueue each unvisited neighbour. Its time complexity is O(V + E). Applications include shortest path in unweighted graphs, web crawling, and network broadcasting.
Q. Given a string and a pattern, find the last occurrence of the pattern in the string
asked 1xmediumStringsTechnical2017
Ans. Use KMP to search the pattern in the string and keep updating a variable with the start index whenever a match is found. After the scan, that variable is the last occurrence, or -1 if no match exists. The key data structure is the LPS array. Time complexity is O(n + m).
Q. Reverse a string without using any variables, using your own string length function
asked 1xmediumStringsTechnical2015
Ans. Reverse it using recursion: write your own length function recursively, then print or build the character at length minus one before recursing on the remaining prefix. This uses the call stack instead of explicit variables. The key detail is that repeated length calculation makes it quadratic unless the length is computed once.
Q. Given a singly linked list, reverse the list whenever a node with value 1 is encountered
asked 1xmediumLinked listsTechnical2017
Ans. Traverse the list once and count nodes whose value is 1; if the count is odd, reverse the whole list, otherwise leave it unchanged. Reversing twice cancels out, so only parity matters. Use standard three pointers, previous, current and next. Time complexity is O(n), space is O(1).
Q. What steps would you take to get code approved and deployed in a production environment?
asked 1xmediumSoftware engineeringManagerial2023
Ans. I would raise a small, well-described pull request, get automated tests and checks passing, request peer review, address feedback, and merge only after approval. Then I would deploy through the agreed CI/CD pipeline, ideally to staging first, verify behaviour, release gradually if possible, and monitor logs, metrics, and errors with a rollback plan ready.
Q. Given C string manipulation code using pointers, explain what the code does and its output
asked 1xmediumCTechnical2016
Ans. The code’s output is the characters reached or changed by the pointer operations, printed up to the first null terminator. To determine it, trace each pointer increment, dereference and assignment in order. The key detail is whether the pointer refers to a mutable char array or an immutable string literal.
Q. Explain the internal working of malloc() and free(); what happens when free(arr+1) is called?
asked 1xmediumOperating systemsTechnical2015
Ans. malloc obtains a block from the heap allocator, records metadata such as size near it, and returns a pointer to usable memory. free expects exactly that returned pointer, uses the metadata to mark the block free, and may coalesce neighbours. Calling free(arr+1) is undefined behaviour because it is not the original allocated pointer.
Q. How do you identify and handle edge cases in a given logic and implement corresponding validations?
asked 1xmediumProgrammingTechnical2023
Ans. I identify edge cases by defining valid input ranges, then testing boundaries, empty values, nulls, duplicates, extreme sizes, and invalid states. I handle them with explicit validations before core logic, clear error handling, and targeted tests. The key detail is to validate assumptions at system boundaries so the main logic stays simple and predictable.
Q. What are balanced binary search trees and what are the different types of rotations in an AVL tree?
asked 1xmediumTreesTechnical2017
Ans. Balanced binary search trees keep their height small, so search, insert and delete stay O(log n). An AVL tree does this by keeping each node’s left and right subtree heights within one. Its rotations are left rotation, right rotation, left-right rotation and right-left rotation, used after insertion or deletion.
Q. If you make a critical mistake just before a production release, how would you handle the situation?
asked 1xmediumConflict resolutionManagerial2023
Ans. Pick a real incident where you acted quickly, stayed calm, and protected customers over ego. Emphasise immediate escalation, clear impact assessment, rollback or fix options, and honest communication with stakeholders. Interviewers listen for ownership, judgement under pressure, no blame shifting, learning afterwards, and respect for release controls.
Q. Given marks of 240 students, generate a report counting students in ranges (0–10, 11–20, ..., 91–100)
asked 1xmediumHashingTechnical2016
Ans. Use an array of 10 counters, one for each mark range, and scan the 240 marks once. For each mark, compute its bucket as 0 for mark 0, otherwise (mark - 1) / 10, then increment that counter. Finally print all ranges with counts. Time complexity is O(n), space is O(1).
Q. Given a C structure array and pointer manipulation code, determine which values change and explain why
asked 1xmediumCTechnical2016
Ans. Only the structure fields modified through a pointer to an array element change in the original array. Assigning a structure to another variable makes a copy, so changes to that copy do not affect the array. Pointer arithmetic selects different elements, while the arrow operator modifies the object the pointer currently addresses.
Q. What is a compiler? Difference between compiler and interpreter; explain how a compiler works internally
asked 1xmediumCompiler designTechnical2015
Ans. A compiler translates an entire source program into machine code or another target form before execution. An interpreter executes source code step by step at runtime. Internally, a compiler typically performs lexical analysis, parsing, semantic checks, intermediate code generation, optimisation, and final code generation, reporting errors before the program runs.
Q. Perform binary search on an array that can be either ascending or descending by first detecting the order
asked 1xmediumBinary searchTechnical2016
Ans. Detect the order by comparing the first and last elements, then run binary search with the comparison direction adjusted. If ascending, move right when the middle value is smaller than the target; if descending, move right when it is larger. The data structure is the array itself, and time complexity is O(log n).
Q. Given a sample coding problem, discuss possible edge cases and how to implement corresponding validations.
asked 1xmediumProgrammingTechnical2023
Ans. Identify edge cases from the input contract, boundary values, empty data, duplicates, invalid types, overflow, ordering assumptions, and impossible states. Validate inputs before the main logic, return agreed errors or defaults, and add tests for each case. The key detail is separating validation from algorithm logic so correctness and complexity remain clear.
Q. What is hashing? Explain different hashing techniques and how hashing is implemented internally in C++ STL
asked 1xmediumHashingTechnical2015
Ans. Hashing maps a key to an array index using a hash function, giving average constant time search, insert and delete. Common techniques include division, multiplication and universal hashing, with collision handling by chaining or open addressing. C++ STL unordered_map and unordered_set use hash tables, std::hash, buckets and usually separate chaining, with rehashing when load factor grows.
Q. Design an ML-based solution to reduce food wastage in a mess, including feature selection and classification
asked 1xmediumMachine learningTechnical2017
Ans. Build a demand prediction system that classifies each meal slot as low, normal, or high demand, then recommends cooking quantities. Use features such as day, meal type, menu items, attendance, holidays, weather, exams, past consumption, and past wastage. Train a classifier like random forest or gradient boosting, monitor prediction error, and retrain regularly with actual leftovers.
Q. Given a general scenario, design an appropriate solution
asked 1xunknownDesignTechnical2015
Ans. Start by clarifying the goal, scale, users, data, latency, availability, and constraints, then propose the simplest architecture that meets them. Define APIs, data model, storage choice, core services, caching, queues, and failure handling. The key detail is explaining trade-offs, such as consistency versus availability, rather than naming technologies blindly.
Showing 60 of 134 questions. Ranked by how often the same question came back across interviews.