Cisco
50+ Doolally Interview Questions and Answers
Q1. Apple Pickup Problem Statement
Alice has a garden represented as a ‘N’ * ‘N’ grid called ‘MATRIX’. She wants to collect apples following these rules:
1
-> Alice can pick an apple from this cell and pass throug...read more
The problem involves finding the maximum number of apples Alice can collect in a grid while following specific rules.
Create a recursive function to explore all possible paths from the starting point to the ending point while keeping track of the collected apples.
Consider the constraints and optimize the solution to avoid unnecessary computations.
Use dynamic programming to store and reuse the results of subproblems to improve efficiency.
Ensure to handle cases where there is no...read more
Q2. Snake and Ladder Problem Statement
Given a 'Snake and Ladder' board with N rows and N columns, where positions are numbered from 1 to (N*N) starting from the bottom left, alternating direction each row, find th...read more
Find the minimum number of dice throws required to reach the last cell on a 'Snake and Ladder' board.
Start from the bottom left cell and move according to dice outcomes (1-6).
Utilize snakes and ladders to reach the last cell faster.
Keep track of the minimum number of throws required to reach the last cell.
If unreachable, return -1 as output.
Implement Stack with Linked List
Your task is to implement a Stack data structure using a Singly Linked List.
Explanation:
Create a class named Stack
which supports the following operations, each in O(1) time:
Implement a Stack data structure using a Singly Linked List with operations in O(1) time.
Create a class named Stack with getSize, isEmpty, push, pop, and getTop methods.
Use a Singly Linked List to store the elements of the stack.
Ensure each operation runs in constant time complexity.
Handle edge cases like empty stack appropriately.
Example: If input is '5 3 10 5 1 2 4', the output should be '10 1 false'.
Q4. Cycle Detection in a Singly Linked List
Determine if a given singly linked list of integers forms a cycle or not.
A cycle in a linked list occurs when a node's next
points back to a previous node in the list. T...read more
Detect if a singly linked list forms a cycle by checking if a node's next points back to a previous node.
Use Floyd's Tortoise and Hare algorithm to detect a cycle in the linked list.
Initialize two pointers, slow and fast, and move them at different speeds to detect a cycle.
If there is a cycle, the fast pointer will eventually catch up to the slow pointer.
If the fast pointer reaches the end of the list (null), there is no cycle.
Q5. Find the Lone Set Bit
Your task is to identify the position of the only '1' bit in the binary representation of a given non-negative integer N
. The representation contains exactly one '1' and the rest are '0's....read more
Find the position of the lone '1' bit in the binary representation of a given non-negative integer.
Iterate through the bits of the integer to find the position of the lone '1'.
Use bitwise operations to check if there is exactly one '1' bit in the binary representation.
Return the position of the lone '1' or -1 if there isn't exactly one '1'.
Q6. Intersection of Linked List Problem
You are provided with two singly linked lists containing integers, where both lists converge at some node belonging to a third linked list.
Your task is to determine the data...read more
Find the node where two linked lists merge, return -1 if no merging occurs.
Traverse both lists to find their lengths and the difference in lengths
Move the pointer of the longer list by the difference in lengths
Traverse both lists simultaneously until they meet at the merging point
Q7. Find All Pairs Adding Up to Target
Given an array of integers ARR
of length N
and an integer Target
, your task is to return all pairs of elements such that they add up to the Target
.
Input:
The first line conta...read more
Given an array of integers and a target, find all pairs of elements that add up to the target.
Iterate through the array and for each element, check if the target minus the element exists in a hash set.
If it exists, add the pair to the result. If not, add the element to the hash set.
Handle cases where the same element is used twice to form a pair.
Return (-1, -1) if no pair is found.
Q8. Word Break Problem Statement
You are given a list of N
strings called A
. Your task is to determine whether you can form a given target string by combining one or more strings from A
.
The strings from A
can be u...read more
Given a list of strings, determine if a target string can be formed by combining one or more strings from the list.
Iterate through all possible combinations of strings from the list to check if they form the target string.
Use recursion to try different combinations of strings.
Optimize the solution by using memoization to store intermediate results.
Handle edge cases like empty input or target string.
Q9. Ways To Make Coin Change
Given an infinite supply of coins of varying denominations, determine the total number of ways to make change for a specified value using these coins. If it's not possible to make the c...read more
The task is to find the total number of ways to make change for a specified value using given denominations.
Use dynamic programming to solve this problem efficiently.
Create a 1D array to store the number of ways to make change for each value from 0 to the target value.
Iterate through the denominations and update the array based on the current denomination.
The final answer will be the value at the target index of the array.
Q10. Add Two Numbers Represented as Linked Lists
Given two linked lists representing two non-negative integers, where the digits are stored in reverse order (i.e., starting from the least significant digit to the mo...read more
Add two numbers represented as linked lists in reverse order and return the sum as a linked list.
Traverse both linked lists simultaneously while keeping track of carry.
Create a new linked list to store the sum digits.
Handle cases where one list is longer than the other or there is a final carry.
Remember to reverse the final linked list before returning the head.
Q11. Anagram Pairs Verification Problem
Your task is to determine if two given strings are anagrams of each other. Two strings are considered anagrams if you can rearrange the letters of one string to form the other...read more
Check if two strings are anagrams of each other by comparing their sorted characters.
Sort the characters of both strings and compare them.
Use a dictionary to count the frequency of characters in each string and compare the dictionaries.
Ensure both strings have the same length before proceeding with comparison.
Example: For input 'spar' and 'rasp', after sorting both strings, they become 'aprs' which are equal, so return True.
Q12. Maximum Path Sum Between Two Leaves
Given a non-empty binary tree where each node has a non-negative integer value, determine the maximum possible sum of the path between any two leaves of the given tree.
Expla...read more
Find the maximum path sum between two leaf nodes in a binary tree.
Traverse the tree to find the maximum path sum between two leaf nodes
Consider both cases where the path passes through the root and where it doesn't
Keep track of the maximum sum while traversing the tree
Q13. LRU Cache Design Question
Design a data structure for a Least Recently Used (LRU) cache that supports the following operations:
1. get(key)
- Return the value of the key if it exists in the cache; otherwise, re...read more
Design a Least Recently Used (LRU) cache data structure that supports get and put operations with capacity constraint.
Implement a doubly linked list to maintain the order of recently used keys.
Use a hashmap to store key-value pairs for quick access.
When capacity is reached, evict the least recently used item before inserting a new item.
Update the position of a key in the linked list whenever it is accessed or updated.
Handle get and put operations efficiently to maintain the L...read more
Q14. Rat In a Maze Problem Statement
Given a N * N
maze with a rat placed at position MAZE[0][0]
, find and print all possible paths for the rat to reach its destination at MAZE[N-1][N-1]
. The rat is allowed to move ...read more
Find all possible paths for a rat in a maze to reach its destination.
Use backtracking to explore all possible paths in the maze.
Mark visited cells and backtrack when reaching dead ends.
Print the path when reaching the destination cell.
Consider all possible movements: left, right, up, and down.
Ensure the rat can only move through cells marked as 1.
Q15. Spiral Order Traversal of a Binary Tree
Given a binary tree with N
nodes, your task is to output the Spiral Order traversal of the binary tree.
Input:
The input consists of a single line containing elements of ...read more
Implement a function to return the spiral order traversal of a binary tree.
Traverse the binary tree in a spiral order, alternating between left to right and right to left at each level
Use a queue to keep track of nodes at each level and a flag to switch direction
Return the list of nodes in spiral order traversal
Q16. Level Order Traversal Problem Statement
Given a binary tree of integers, return the level order traversal of the binary tree.
Input:
The first line contains an integer 'T', representing the number of test cases...read more
Return the level order traversal of a binary tree given in level order with null nodes represented by -1.
Create a queue to store nodes for level order traversal
Start with the root node, enqueue it, then dequeue and print its value, enqueue its children, repeat until queue is empty
Handle null nodes represented by -1 by skipping them during traversal
Q17. Longest Substring Without Repeating Characters Problem Statement
Given a string S
of length L
, determine the length of the longest substring that contains no repeating characters.
Example:
Input:
"abacb"
Output...read more
Find the length of the longest substring without repeating characters in a given string.
Use a sliding window approach to keep track of the longest substring without repeating characters.
Use a hashmap to store the index of each character as it appears in the string.
Update the start index of the window when a repeating character is found.
Calculate the maximum length of the window as you iterate through the string.
Return the maximum length as the result.
Q18. Longest Subarray Zero Sum Problem Statement
Given an array of integers arr
, determine the length of the longest contiguous subarray that sums to zero.
Input:
N (an integer, the length of the array)
arr (list of ...read more
Find the length of the longest contiguous subarray that sums to zero in an array of integers.
Use a hashmap to store the cumulative sum and its corresponding index.
Iterate through the array, updating the sum and checking if the current sum exists in the hashmap.
If the sum exists in the hashmap, update the maximum length of subarray with sum zero.
Return the maximum length of subarray with sum zero.
Q19. Detect and Remove Loop in Linked List
For a given singly linked list, identify if a loop exists and remove it, adjusting the linked list in place. Return the modified linked list.
Expected Complexity:
Aim for a...read more
Detect and remove loop in a singly linked list in place with O(n) time complexity and O(1) space complexity.
Use Floyd's Cycle Detection Algorithm to identify the loop in the linked list.
Once the loop is detected, use two pointers to find the start of the loop.
Adjust the pointers to remove the loop and return the modified linked list.
Use two wires of different lengths to measure a specific amount of time by burning them simultaneously.
Burn both wires at the same time, one wire will finish burning before the other
Measure the time it takes for the first wire to burn completely
Use this time as a reference to measure the specific amount of time by burning the second wire
An IP address is a unique numerical label assigned to each device connected to a computer network, typically represented by 32 bits.
An IP address is used to identify and locate devices on a network.
It consists of four sets of numbers separated by periods, such as 192.168.1.1.
IPv4 addresses are 32 bits long, while IPv6 addresses are 128 bits long.
A router is a networking device that forwards data packets between computer networks. It differs from a gateway in terms of functionality and scope.
A router operates at the network layer of the OSI model, making decisions based on IP addresses.
Routers connect multiple networks together and determine the best path for data to travel.
Gateways, on the other hand, translate between different types of networks or protocols.
Gateways operate at the application layer of the OSI model...read more
MAC addresses are necessary for local network communication and are used to uniquely identify devices on a network.
MAC addresses are used at the data link layer of the OSI model to identify devices within the same local network.
IP addresses are used at the network layer to identify devices across different networks.
MAC addresses are hardcoded into network interface cards (NICs) and are used for communication within the same network segment.
MAC addresses are essential for Ethe...read more
Friend class and function in OOP allows specific classes or functions to access private and protected members of a class.
Friend class/function can access private and protected members of a class without violating encapsulation.
It allows for selective sharing of data between classes without exposing all members to the outside world.
Friendship is not mutual - a class can declare another class as a friend, but the other class does not automatically become a friend.
Example: In a ...read more
To measure exactly 4 liters of water, fill the 3-liter can, pour it into the 5-liter can, refill the 3-liter can, pour enough to fill the 5-liter can, leaving 1 liter in the 3-liter can, then empty the 5-liter can and pour the remaining 1 liter from the 3-liter can into the 5-liter can, finally refill the 3-liter can and pour it into the 5-liter can to get exactly 4 liters.
Fill the 3-liter can and pour it into the 5-liter can.
Refill the 3-liter can and pour enough to fill the...read more
Object Oriented Programming concepts include encapsulation, inheritance, polymorphism, and abstraction.
Encapsulation: Bundling data and methods that operate on the data into a single unit (class). Example: Class Car with properties like color and methods like drive().
Inheritance: Creating new classes based on existing classes, inheriting their attributes and methods. Example: Class SUV inheriting from class Car.
Polymorphism: Objects of different classes can be treated as obje...read more
ArrayList is implemented using a dynamic array while LinkedList is implemented using a doubly linked list.
ArrayList provides fast random access but slow insertion and deletion operations.
LinkedList provides fast insertion and deletion operations but slow random access.
Example: ArrayList is suitable for scenarios where frequent access and traversal of elements is required, while LinkedList is suitable for scenarios where frequent insertion and deletion of elements is required.
Abstraction focuses on hiding implementation details, while inheritance allows a class to inherit properties and behavior from another class.
Abstraction is the concept of hiding the complex implementation details and showing only the necessary features of an object.
Inheritance is a mechanism where a new class inherits properties and behavior from an existing class.
Abstraction is achieved through interfaces and abstract classes, while inheritance is implemented using the 'exte...read more
Different types of semaphores include binary semaphores, counting semaphores, and mutex semaphores.
Binary semaphores: Can only have two states - 0 or 1. Used for mutual exclusion.
Counting semaphores: Can have multiple states. Used for synchronization among multiple processes.
Mutex semaphores: Similar to binary semaphores but with additional features like priority inheritance and deletion safety.
The OSI Reference Model is a conceptual framework that standardizes the functions of a telecommunication or computing system into seven layers.
The OSI Reference Model stands for Open Systems Interconnection Reference Model.
It consists of seven layers: Physical, Data Link, Network, Transport, Session, Presentation, and Application.
Each layer has specific functions and communicates with the adjacent layers.
The model helps in understanding how different networking protocols work...read more
Memory protection in operating systems is a mechanism to prevent a process from accessing memory that has not been allocated to it.
Memory protection prevents a process from accessing memory locations outside its allocated space.
It helps in preventing one process from interfering with the memory of another process.
Operating systems use techniques like virtual memory and access control lists to implement memory protection.
Examples include segmentation fault in Unix systems when...read more
IPv6 has a larger address space, improved security features, and better support for mobile devices compared to IPv4.
IPv4 uses 32-bit addresses while IPv6 uses 128-bit addresses.
IPv4 supports around 4.3 billion unique addresses, whereas IPv6 supports 340 undecillion unique addresses.
IPv6 has built-in security features like IPsec, while IPv4 requires additional security protocols.
IPv6 has better support for mobile devices and IoT devices due to its larger address space and impr...read more
During system boot, the BIOS performs Power-On Self Test (POST), loads the operating system, and initializes hardware components.
BIOS (Basic Input/Output System) performs Power-On Self Test (POST) to check hardware components
BIOS loads the bootloader from the boot device (e.g. hard drive, SSD)
Bootloader loads the operating system kernel into memory
Operating system initializes hardware components and starts system services
User login prompt is displayed for user interaction
Thrashing in operating systems is a situation where the system is spending more time swapping data between memory and disk than actually executing tasks.
Occurs when the system is overwhelmed with too many processes competing for limited resources
Results in a decrease in overall system performance
Can be alleviated by optimizing memory usage or adding more physical memory
Example: A system with insufficient RAM running multiple memory-intensive applications
A static member in C++ is a member of a class that is shared among all instances of the class.
Static members are declared using the 'static' keyword.
They are not associated with any specific instance of the class, but rather with the class itself.
They can be accessed using the scope resolution operator '::'.
Static members are commonly used for constants, utility functions, or shared data among all instances of a class.
C++ supports polymorphism through virtual functions and inheritance.
C++ supports polymorphism through virtual functions and inheritance
Virtual functions allow a function to be overridden in a derived class
Base class pointers can point to derived class objects, enabling polymorphic behavior
Example: class Animal { virtual void makeSound() { cout << 'Animal sound'; } }; class Dog : public Animal { void makeSound() { cout << 'Bark'; } };
Example: Animal* a = new Dog(); a->makeSoun...read more
Q37. When the looping state ments are used? What are branching statements explain breafly?
Looping statements are used to execute a block of code repeatedly. Branching statements alter the flow of control in a program.
Looping statements are used when we want to execute a block of code repeatedly until a certain condition is met.
Examples of looping statements include for, while, and do-while loops.
Branching statements are used to alter the normal flow of control in a program.
Examples of branching statements include if-else statements, switch statements, and the brea...read more
Piping in Unix/Linux allows the output of one command to be used as the input for another command.
Piping is done using the | symbol
Multiple commands can be piped together
Piping allows for the creation of complex command chains
Example: ls -l | grep txt
A static variable in C is a variable that retains its value between function calls.
Static variables are declared using the 'static' keyword.
They are initialized only once and retain their value throughout the program's execution.
Static variables have a default value of 0 if not explicitly initialized.
They are stored in the data segment of the program's memory.
Example: static int count = 0; declares a static variable 'count' with an initial value of 0.
DNS stands for Domain Name System, which translates domain names to IP addresses.
DNS is like a phone book for the internet, translating human-readable domain names (like google.com) to IP addresses (like 172.217.3.206).
It helps users access websites by typing in easy-to-remember domain names instead of complex IP addresses.
DNS servers store records of domain names and their corresponding IP addresses, allowing for efficient and quick lookups.
DNS also plays a role in email del...read more
A namespace in C++ is a declarative region that provides a scope for the identifiers within it.
Namespaces help in organizing code by grouping related classes, functions, and variables.
They prevent naming conflicts by allowing the same name to be used in different namespaces.
Example: namespace myNamespace { int x; }
Example: using namespace std; // for using standard library functions without prefix
Priority inversion is a scenario in scheduling where a lower priority task holds a resource needed by a higher priority task, causing the higher priority task to wait.
Occurs when a low priority task locks a resource needed by a high priority task
Results in the high priority task being blocked and unable to proceed
Can lead to delays in critical tasks and impact system performance
Commonly addressed through priority inheritance or priority ceiling protocols
ARP stands for Address Resolution Protocol, used to map IP addresses to MAC addresses in a local network.
ARP is used to find the MAC address of a device based on its IP address
It operates at the data link layer of the OSI model
ARP requests are broadcasted to all devices on the local network
Example: When a device wants to communicate with another device on the same network, it uses ARP to find the MAC address of the destination device
Q44. What is Python?how if state ments are used?
Python is a high-level, interpreted programming language known for its simplicity and readability.
Python is used for web development, data analysis, artificial intelligence, and more.
It uses if statements for conditional execution of code.
Example: if x > 5: print('x is greater than 5')
Python also supports elif and else statements for more complex conditions.
Q45. Program to convert 24hr input into AM-PM formatted output
Program to convert 24hr input into AM-PM formatted output
Create a function that takes a 24-hour time input as a string
Use the datetime module in Python to convert the input to a datetime object
Format the datetime object to display in AM-PM format
Return the formatted time as a string
Q46. Two sum - brute and optimal approach
Two sum problem involves finding two numbers in an array that add up to a specific target.
Brute force approach involves nested loops to check all possible pairs of numbers.
Optimal approach uses a hashmap to store the difference between target and current number.
Example: nums = [2, 7, 11, 15], target = 9. Optimal solution: [0, 1] (2 + 7 = 9).
Q47. what are oops, explain
Object-oriented programming concepts that focus on objects and classes for code organization and reusability.
Encapsulation: bundling data and methods that operate on the data into a single unit (class)
Inheritance: ability of a class to inherit properties and behavior from another class
Polymorphism: ability to present the same interface for different data types
Q48. longest subarray with sum 0
Find the longest subarray with sum 0 in an array of integers.
Use a hash table to store the sum and its index.
Iterate through the array and calculate the cumulative sum.
If the cumulative sum is already in the hash table, then the subarray between the current index and the index in the hash table has a sum of 0.
Keep track of the longest subarray with sum 0 seen so far.
Return the length of the longest subarray with sum 0.
Q49. IMplement LRU cache
LRU cache is a data structure that stores the most recently used items, discarding the least recently used items when full.
Use a doubly linked list to keep track of the order of items based on their usage.
Use a hashmap to quickly access items in the cache.
When a new item is accessed, move it to the front of the linked list and update the hashmap.
When the cache is full, remove the least recently used item from the end of the linked list and the hashmap.
Q50. sum of 2 linkedlist
Add the values of two linked lists and return the sum as a new linked list.
Traverse both linked lists simultaneously and add the corresponding values along with any carry from the previous sum.
Handle cases where one linked list is longer than the other by considering the remaining nodes and any carry.
Create a new linked list to store the sum values and return it as the result.
Interview Process at Doolally
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month