Snapdeal
100+ Interview Questions and Answers
You are given an array containing 'N' points in the plane. The task is to find out the distance of the closest points.
Note :
Where distance between two points (x1, y1) and (x2, y2) is cal...read more
Given two binary trees T and S, check whether tree S has exactly the same structure and node values with a subtree of T, i.e., check if tree S is a subtre...read more
You have been given an array/list 'HEIGHTS' of length ‘N. 'HEIGHTS' represents the histogram and each element of 'HEIGHTS' represents the height of the histogram bar. Cons...read more
You have given a Singly Linked List of integers, determine if it forms a cycle or not.
A cycle occurs when a node's next points back to a previous node in the list. The linked list i...read more
You are given a positive integer ‘N’. Your task is to find the total number of ‘1’ in the binary representation of all the numbers from 1 to N.
Since the count of ‘1’ can be huge, yo...read more
You have been given a Binary Tree of 'N' nodes, where the nodes have integer values. Your task is to find the In-Order traversal of the given binary tree.
For e...read more
You are given an N * N matrix of integers where each row and each column is sorted in increasing order. You are given a target integer 'X'. Find the position of...read more
You have been given a Binary Tree of distinct integers and two nodes ‘X’ and ‘Y’. You are supposed to return the LCA (Lowest Common Ancestor) of ‘X’ and ‘Y’.
The LCA of ‘X’ and ‘Y’ in the bina...read more
You are given a Binary Search Tree (BST) and a target value ‘K’. Your task is to check if there exist two unique elements in the given BST such that their sum is equal to ...read more
You are given a Singly Linked List of integers. You need to reverse the Linked List by changing the links between nodes.
Input Format :
The first line of input contains a single integer T, ...read more
You are given an arbitrary grid with M rows and N columns. You have to print the total number of rectangles which can be formed using the rows and columns of this grid. In simple...read more
Nth term of Fibonacci series F(n), where F(n) is a function, is calculated using the following formula -
F(n) = F(n-1) + F(n-2), Where, F(1) = F(2) = 1
Provided N you have to find out the Nth Fib...read more
You have been given a string STR and a non-empty string PTR. Your task is to find all the starting indices of PTR’s anagram in STR.
An anagram of a string is another string which co...read more
Given a binary tree, return the zigzag level order traversal of the nodes' values of the given tree. Zigzag traversal means starting from left to right, then right to left for the next lev...read more
Q15. You have a deck of 10 cards.You take one card out and put it on table and put next card in the end of deck.You repeat this sequence till all cards are on the table.Sequence formed on the table is 1,2,3,4,5…10. ...
read moreReconstruct original sequence of cards given a specific sequence of cards placed on table.
The last card placed on the table must be 10.
The second last card placed on the table must be 5 or 6.
The first card placed on the table must be either 1 or 2.
Use trial and error method to reconstruct the original sequence.
You are given an Integer array ‘ARR’ and an Integer ‘K’. Your task is to find the ‘K’ most frequent elements in ‘ARR’. Return the elements sorted in ascending or...read more
You're given string ‘STR’ consisting solely of “{“, “}”, “(“, “)”, “[“ and “]” . Determine whether the parentheses are balanced.
Input Format:
The first line cont...read more
Given a binary tree having a positive integer written on each of its nodes. Your task is to find the vertical sum of node values i.e. the sum of nodes that can be connected by...read more
Q19. There is a file which contains ip addresses and corresponding url. Example 192.168.1.15 www.abc.com 10.255.255.40 ----- You have to return the subnet mask of the ip and the url after “www.” Output 192.168.1 abc...
read moreJava function to return subnet mask of IP and URL after www.
Read the file and store IP addresses and URLs in separate arrays
Use regex to extract subnet mask from IP address
Use substring to extract URL after www.
Return subnet mask and URL as separate strings
You are given an arbitrary binary tree consisting of N nodes, where each node is associated with a certain value, your task is to find the maximum sum for a level in the tre...read more
You are given a string S which represents a number. You have to find the smallest number strictly greater than the given number which contains the same set of dig...read more
Three couples are on the vacation.They need to cross the river to reach their hotel. There are 3 rules which are as follows:-
Rule 1:- The boat can only carry two people at a time. If the third person tryi...read more
Ninja has been given two sorted integer arrays/lists ‘ARR1’ and ‘ARR2’ of size ‘M’ and ‘N’. Ninja has to merge these sorted arrays/lists into ‘ARR1’ as one sorted array. You may have to a...read more
Q24. How would you design DBMS for Snapdeal’s website’s shoe section. Now if you want to further break it into Sports and Casual Shoe would you break the DB into two or add another entity?
For Snapdeal's shoe section, I would design a DBMS with separate entities for Sports and Casual Shoes.
Create a main entity for shoes with attributes like brand, size, color, etc.
Create separate entities for Sports and Casual Shoes with attributes specific to each category.
Link the Sports and Casual Shoe entities to the main Shoe entity using a foreign key.
Use indexing and normalization techniques to optimize performance and reduce redundancy.
Consider implementing a search fea...read more
Print "Hello" and "world" multiple times using two threads in java.
Follow up questions :
-- Why sleep() cannot be used?
– Why have you used synchronized keyword?
– How will a deadlock occ...read more
Q26. You are given two ropes.Each rope takes exactly 1 hour to burn. How will you measure period of 45 minutes
Burn one rope from both ends and the other rope from one end.
Light one rope from both ends and the other rope from one end.
When the first rope burns completely, 30 minutes have passed.
Then, immediately light the other end of the second rope.
When the second rope burns completely, 15 more minutes have passed.
Total time elapsed is 45 minutes.
Q27. There are two sorted arrays. First one is of size m+n containing only ‘first’ m elements. Another one is of size n and contains n elements. Merge these two arrays into the first array of size m+n such that the ...
read moreMerge two sorted arrays into one sorted array of larger size
Create a new array of size m+n
Compare the last elements of both arrays and insert the larger one at the end of the new array
Repeat until all elements are merged
If any elements are left in the smaller array, insert them at the beginning of the new array
Time complexity: O(m+n)
Example: arr1=[1,3,5,7,0,0,0], arr2=[2,4,6], output=[1,2,3,4,5,6,7]
Q28. Variation of -----/ Given a dictionary of words and a number n. Find count of all words in dictionary that can be formed by given number n
The question asks to find the count of words in a dictionary that can be formed by a given number.
Iterate through each word in the dictionary
Check if the characters in the word can be formed using the given number
Increment the count if the word can be formed
Q29. Cube with six colors how many different cubes can be obtained?
There are 6 colors, so 6^3 = 216 different cubes can be obtained.
The cube has 6 faces, each of which can be one of 6 colors.
Therefore, there are 6 options for the first face, 6 for the second, and 6 for the third.
To find the total number of possible cubes, we multiply these options together: 6 x 6 x 6 = 216.
Q30. DNS – Domain name servers : what are they , how do they operate?
DNS servers translate domain names into IP addresses to enable communication between devices on the internet.
DNS servers act as a phone book for the internet, translating domain names into IP addresses.
When a user types a domain name into their browser, the browser sends a request to a DNS server to resolve the domain name into an IP address.
DNS servers operate in a hierarchical system, with root servers at the top, followed by top-level domain servers, and then authoritative...read more
Q31. Calculate what single cut bookmyshow should charge from the customers depending on the various factor..... Ans. List the factors like movie of superstar, festival occasion etc.
BookMyShow should charge different prices based on factors like movie of superstar, festival occasion, etc.
Consider the popularity of the movie star
Take into account the demand for tickets during festival occasions
Analyze the competition and market trends
Offer discounts for bulk bookings or loyalty programs
Consider the cost of production and distribution
Adjust prices based on the time of day or week
Use dynamic pricing to optimize revenue
Examples: Charge higher prices for a mo...read more
Q32. How to eliminate a defective pack (empty) from a bunch of non-empty ones while loading for transportation?
Defective pack elimination during transportation loading
Inspect each pack before loading
Use a checklist to ensure all packs are accounted for
Separate defective packs from non-defective ones
Label defective packs clearly
Dispose of defective packs properly
Train personnel on proper handling procedures
There are three equal rows that consist of three dots each. What you have to do is to draw four straight lines to connect all of the dots. However, the challenge is to avoid lifting the pencil off the pap...read more
Q34. How are you suppose to deal with a customer who is already pissed off with the previous executive that he/she had talked to?
When dealing with a customer who is already upset with a previous executive, it is important to empathize, listen actively, apologize if necessary, and offer a solution or escalate the issue if needed.
Empathize with the customer and acknowledge their frustration.
Listen actively to understand their concerns and let them vent if necessary.
Apologize for any inconvenience caused by the previous executive, even if it wasn't your fault.
Offer a solution or alternative to address the...read more
Q35. Lowest Common Ancestor of two nodes in binary tree.I wrote code for this.Then interviewer drew a tree and asked to print stacktrace on it
Finding lowest common ancestor of two nodes in binary tree
Traverse the tree from root to both nodes and store the paths in separate arrays
Compare the paths to find the last common node
Return the last common node as the lowest common ancestor
Use recursion to traverse the tree efficiently
Q36. Write a code to find if the input date is today or tomorrow based on the current date. If it's not today or tomorrow, output the no of days difference between the input date and the current date.
Code to find if input date is today/tomorrow or no of days difference from current date.
Get current date using Date() constructor
Convert input date to Date object
Compare input date with current date to check if it's today/tomorrow
If not, calculate the difference in days using getTime() method
Output the result accordingly
Q37. Find LCM of all numbers from 1 to n. Give an algorithm, then correctly estimate the time complexity
Algorithm to find LCM of all numbers from 1 to n and its time complexity
Find prime factors of all numbers from 1 to n
For each prime factor, find the highest power it appears in any number from 1 to n
Multiply all prime factors raised to their highest power to get LCM
Time complexity: O(n*log(log(n)))
How to Measure 45 minutes using two identical wires?
Q39. Explain box model in css, and what is specificity in CSS. What are render-blocking statements?
Box model defines how elements are rendered in CSS. Specificity determines which CSS rule applies to an element. Render-blocking statements delay page rendering.
Box model includes content, padding, border, and margin.
Specificity is calculated based on the number of selectors and their types.
Render-blocking statements are CSS or JavaScript files that prevent the page from rendering until they are loaded.
Use media queries to optimize rendering and reduce render-blocking stateme...read more
Q40. calculate the top 10 words , which comes frequently in 1 hour time span , on facebook, (dynamically)
Calculate top 10 frequently used words on Facebook in 1 hour dynamically.
Use Facebook API to fetch data
Implement a script to count word frequency
Sort the words based on frequency and return top 10
Q41. What is event bubbling, event capturing and its use?
Event bubbling and event capturing are two mechanisms in JavaScript that describe the order in which events are handled.
Event bubbling is the process where an event is first captured by the innermost element and then propagated to its parent elements.
Event capturing is the opposite process where an event is first captured by the outermost element and then propagated to its child elements.
Event bubbling is the default behavior in most browsers.
Event.stopPropagation() can be us...read more
Q42. How will you implement infinite scrolling in react js?
Implement infinite scrolling in React JS using Intersection Observer API.
Use Intersection Observer API to detect when the user has scrolled to the bottom of the page.
Fetch new data and append it to the existing data using setState.
Use a loading spinner to indicate that new data is being fetched.
Add a debounce function to prevent multiple API calls while scrolling.
Use a key prop when rendering the list of data to avoid re-rendering of existing elements.
How do we measure forty-five minutes using two identical wires, each of which takes an hour to burn? We have matchsticks with us. The wires burn non-uniformly.
Q44. There is four digit number in aabb form and it is a perfect square.Find out the number
The number is 7744.
The number must end in 00 or 44.
The square root of the number must be a whole number.
The only possible number is 7744.
Q45. A linked list contains loop.Find the length of non looped linked list
To find the length of non-looped linked list, we need to traverse the list and count the number of nodes.
Traverse the linked list using a pointer and count the number of nodes until the end of the list is reached.
If a loop is encountered, break out of the loop and continue counting until the end of the list.
Return the count as the length of the non-looped linked list.
Q46. In a matrix of only 0’s and 1’s, where in each row, there are only 0’s first and then 1’s, find the row with maximum number of 1’s. [Start with right top corner O(m+n) ] [With Code]
Q47. Tell about Saas( Syntactically Awesome Style Sheets)
Saas is a CSS preprocessor that extends the functionality of CSS with variables, mixins, and more.
Saas stands for Syntactically Awesome Style Sheets
It allows for the use of variables, mixins, and functions in CSS
Saas code must be compiled into CSS before it can be used in a web page
Saas is often used in conjunction with build tools like Gulp or Webpack
Q48. What are inner join and outer join in sql
Inner join returns only the matching rows between two tables, while outer join returns all rows from one table and matching rows from the other.
Inner join combines rows from two tables based on a matching column.
Outer join returns all rows from one table and matching rows from the other.
Left outer join returns all rows from the left table and matching rows from the right table.
Right outer join returns all rows from the right table and matching rows from the left table.
Full ou...read more
Q49. Two linked list are merging at a point.Find merging point
To find the merging point of two linked lists
Traverse both linked lists and find their lengths
Move the pointer of the longer list by the difference in lengths
Traverse both lists simultaneously until they meet at the merging point
Q50. Why Snapdeal (or whatever company it is)?
Snapdeal is a leading e-commerce company in India with a strong customer base and a wide range of products.
Snapdeal has a large customer base in India, which provides a great opportunity for growth and impact.
The company offers a wide range of products across various categories, catering to diverse customer needs.
Snapdeal has a strong presence in the e-commerce market, competing with other major players.
The company has a user-friendly platform and offers convenient payment op...read more
Q51. Write code to find if two objects are equal or not in javascript
Code to check equality of two objects in JavaScript
Use the JSON.stringify() method to convert the objects into strings
Compare the string representations of the objects using the === operator
If the strings are equal, the objects are considered equal
Q52. If a shipment is changed in between i.e. product is replaced by say, a soap how will you tackle this problem?
Q53. Codes for Post-Order, In-Order and Level-Order Traversal of a binary tree.P.S : These questions were asked to my friends
Codes for Post-Order, In-Order, and Level-Order Traversal of a binary tree.
Post-Order Traversal: Left subtree, Right subtree, Root
In-Order Traversal: Left subtree, Root, Right subtree
Level-Order Traversal: Visit nodes level by level, from left to right
Q54. What is bind in javascript and write its polyfill
Bind creates a new function with a specified 'this' value and arguments.
Bind returns a new function with the same body as the original function.
The 'this' value of the new function is bound to the first argument passed to bind().
The subsequent arguments are passed as arguments to the new function.
Polyfill for bind() can be created using call() or apply() methods.
Q55. Create Linked List without using the internal library and provide the functionality of add delete find.
Create Linked List without using internal library and provide add, delete, find functionality.
Create a Node class with data and next pointer
Create a LinkedList class with head pointer and methods to add, delete, and find nodes
Use a loop to traverse the list and perform operations
Handle edge cases such as adding to an empty list or deleting the head node
Q56. Estimate the costs of an Auto-Rickshaw driver. (No time frame)
Estimating the costs of an Auto-Rickshaw driver.
Consider fuel expenses for the auto-rickshaw.
Include maintenance and repair costs.
Factor in license and permit fees.
Account for insurance premiums.
Include daily wages for any helpers or assistants.
Consider miscellaneous expenses like parking fees and tolls.
Q57. Walk be through your CV and explain each thing in detail
I will explain each section of my CV in detail.
Education: I completed my Bachelor's degree in Economics at XYZ University. I focused on macroeconomics and econometrics, conducting research on the impact of fiscal policy on economic growth.
Internship: I interned at ABC Company, where I worked closely with the data analysis team. I gained hands-on experience in data collection, cleaning, and analysis using tools like Excel and SQL.
Work Experience: I worked as a Junior Analyst a...read more
Q59. what is the difference between async and defer
async loads script while page continues to load, defer loads script after page has loaded
async loads scripts asynchronously while page continues to load
defer loads scripts after the page has loaded
async scripts may not execute in order, while defer scripts do
async scripts may cause rendering issues, while defer scripts do not
Q60. How would you tackle a problem from our brand loyal seller?
I would listen to their concerns, empathize with their situation, and work with them to find a solution that meets their needs.
Listen actively to understand their concerns
Acknowledge their loyalty to the brand
Empathize with their situation
Collaborate with them to find a solution that meets their needs
Provide options and alternatives if necessary
Follow up to ensure their satisfaction
Q62. Guess the amount of water used in the college?
The amount of water used in the college depends on various factors such as the number of students, staff, and facilities.
The amount of water used in the college varies depending on the size of the college.
The number of students, staff, and facilities also play a significant role in determining the amount of water used.
The college may have water-saving measures in place to reduce water usage.
The amount of water used may also vary depending on the season and weather conditions....read more
Q63. Mean median mode, why median is best
Median is best because it is not affected by outliers and gives a better representation of central tendency.
Median is the middle value in a dataset, which makes it less affected by extreme values or outliers.
It gives a better representation of central tendency as compared to mean, which can be skewed by outliers.
Mode is not always useful as it may not exist or may not be unique in a dataset.
For example, in a dataset of salaries, the median would give a better representation o...read more
Q64. You are receiving 0/1 in the left side of previous number dynamically and for each insert you have to print whether decimal of new generated number is divisible by 3. Print “YES” or “NO” accordingly
Q66. Calculate the level sum of the binary tree
Calculate the level sum of a binary tree.
Traverse the tree level by level using BFS
Add the values of nodes at each level
Store the level sum in an array
Return the array of level sums
Q67. SQL vs NoSQL. Why NoSQL
NoSQL databases are flexible, scalable, and can handle large amounts of unstructured data.
NoSQL databases are schema-less, allowing for easy and flexible data modeling.
They can handle large amounts of unstructured data, making them suitable for big data applications.
NoSQL databases are highly scalable and can easily handle high traffic and large user bases.
They provide horizontal scalability by distributing data across multiple servers.
NoSQL databases are often used in real-t...read more
Q68. Find the number of connected components [islands] in a matrix formed with only 0’s and 1’s. [With Code] -----/
Q69. You have an sorted array,you have to make a balanced binary search tree from it (only approach) and basic insertion and deletion in BST
Q70. Number of rectangles in MxN matrix
The number of rectangles in an MxN matrix can be calculated using a formula.
The formula is (M * (M + 1) * N * (N + 1)) / 4
The matrix can be divided into smaller sub-matrices to count the rectangles
The number of rectangles can also be calculated by counting all possible pairs of rows and columns
Q71. Find the total no of the island in a 2d matrix. Working code was required.
Find the total no of islands in a 2D matrix.
Use DFS or BFS to traverse the matrix.
Mark visited cells to avoid repetition.
Count the number of islands found.
Q72. If you recieve a damaged product, how will.you deal with customer over the phone?
I would apologize for the inconvenience and assure the customer that we will resolve the issue promptly.
Apologize for the inconvenience caused
Assure the customer that we will resolve the issue
Ask for details about the damaged product
Offer options for replacement, refund, or repair
Provide clear instructions on returning the damaged product
Q73. A simple program to check whether a number is palindrome or not
A program to check if a number is a palindrome or not.
Convert the number to a string
Reverse the string
Compare the reversed string with the original string
If they are the same, the number is a palindrome
Q74. Write a recursive function for nth fibonacci number!Now make some changes in the same code in order to get O(1) complexity in most cases.(Use Dynamic Programming!)
Q75. Given a 2-d array with sorted rows and columns, write efficient code for searching a number!Puzzle : a glass, a tap given! fill the glass half without the use of any measuring instruments!
Q76. You have given two arrays, all the elements of first array is same as second array except 1, You have to find out distinct pair
Q77. Difference between Process and Thread.6. find the number occurring odd number of time (xor solution).-----/
Q78. How will you decide what data structure should use?
Q79. A sorted Array has been rotated r times to the left. find the minimum in least possible time(O(logn) expected). -----/
Q80. Find square root of a number
To find square root of a number, use Math.sqrt() function in JavaScript.
Use Math.sqrt() function in JavaScript to find square root of a number.
For example, Math.sqrt(16) will return 4.
If the number is negative, Math.sqrt() will return NaN.
Q81. Number of rectangles/squares in chess board
There are 204 squares and 1296 rectangles on a standard 8x8 chess board.
The number of squares can be calculated using the formula n(n+1)(2n+1)/6, where n is the number of rows/columns.
The number of rectangles can be calculated using the formula n(n+1)m(m+1)/4, where n and m are the number of rows and columns respectively.
For an 8x8 chess board, there are 64 squares of size 1x1, 49 squares of size 2x2, 36 squares of size 3x3, 25 squares of size 4x4, 16 squares of size 5x5, 9 s...read more
Q82. Design a recommendation system as you see on e-commerce sites recommending the items for you to buy. You just have to tell the ideas and design the classes accordingly
Q83. Number of Umbrella sold in India during rainy seasons
The number of umbrellas sold in India during rainy seasons varies depending on factors such as rainfall intensity and geographical location.
The demand for umbrellas is generally higher in regions with heavy rainfall.
Urban areas with higher population density may have a higher demand for umbrellas.
Factors like price, availability, and marketing strategies also influence umbrella sales.
Sales data from previous years can provide insights into the average number of umbrellas sold...read more
Q84. Which e-commerce site you normally purchase from and why?
Q85. What is pre-order and post-order?
Pre-order and post-order are traversal methods used in binary trees.
Pre-order: visit root, left subtree, right subtree
Post-order: visit left subtree, right subtree, root
Used to traverse binary trees and perform operations on nodes
Example: Pre-order traversal of binary tree: A, B, D, E, C, F, G
Example: Post-order traversal of binary tree: D, E, B, F, G, C, A
Q86. Estimate the revenue of a Dominos outlet
Estimating the revenue of a Dominos outlet
Consider the average number of orders per day
Calculate the average order value
Multiply the average number of orders by the average order value
Take into account any seasonal variations or promotions
Consider the location and population density of the outlet
Analyze the competition in the area
Factor in the operating expenses and profit margin
Q87. Reverse linked list without recursion
Reverse a linked list iteratively
Create three pointers: prev, curr, and next
Initialize prev to null and curr to head
Loop through the list and set next to curr's next node
Set curr's next node to prev
Move prev and curr one step forward
Return prev as the new head
Q88. whether 899 is prime or not??
No, 899 is not a prime number.
A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself.
899 can be divided by 29 and 31, so it is not a prime number.
Q89. How you will improve health of a marketplace
By analyzing data, identifying pain points, and implementing solutions to improve user experience and trust.
Analyze user behavior and feedback to identify areas of improvement
Implement measures to increase transparency and trust, such as user reviews and seller verification
Provide resources and support for dispute resolution
Encourage diversity and inclusivity in the marketplace to attract a wider range of buyers and sellers
Regularly monitor and update policies to ensure compl...read more
Q90. How you will design new customer support system
I will design a customer support system that is user-friendly, efficient, and personalized.
Conduct research to understand customer needs and preferences
Identify common customer issues and develop a knowledge base for quick resolution
Implement a ticketing system to track and prioritize customer inquiries
Integrate chatbots and AI to provide 24/7 support
Train support staff to provide personalized and empathetic service
Collect feedback and analyze data to continuously improve the...read more
Q91. Binary Search in Rotated sorted array. i.e. 567891234
Q92. What are tree traversals?
Tree traversals are methods of visiting all nodes in a tree data structure.
There are three types of tree traversals: in-order, pre-order, and post-order.
In-order traversal visits the left subtree, then the root, then the right subtree.
Pre-order traversal visits the root, then the left subtree, then the right subtree.
Post-order traversal visits the left subtree, then the right subtree, then the root.
Tree traversals are commonly used in searching and sorting algorithms.
Q93. Binary Search in Biotonic sorted array. i.e. 12345XXXXX2
Q94. Different types of traversals of a tree, with example
Q95. What are the goals for the future?
To excel in my role and contribute to the growth of the company.
To learn and master new skills
To exceed performance expectations
To collaborate with team members and share knowledge
To contribute to the company's success through hard work and dedication
Q96. The architecture of the current system.
The current system follows a microservices architecture.
The system is divided into multiple independent services.
Each service has its own database and communicates with other services through APIs.
The architecture allows for scalability and flexibility.
Examples of microservices used in the system include user authentication, payment processing, and inventory management.
Q97. Check if a linked list is palindrome or not
The answer describes how to check if a linked list is a palindrome or not.
Traverse the linked list and store the values in an array
Compare the elements of the array from both ends to check for palindrome
Alternatively, use two pointers to traverse the linked list, one slow and one fast, and reverse the first half of the list while traversing
Q98. What are the demerits in SnapDeal?
Q99. Kth element from the end, of a linked list
To find the Kth element from the end of a linked list, we can use the two-pointer approach.
Initialize two pointers, 'fast' and 'slow', pointing to the head of the linked list.
Move the 'fast' pointer K steps ahead.
Move both 'fast' and 'slow' pointers one step at a time until 'fast' reaches the end of the linked list.
The 'slow' pointer will be pointing to the Kth element from the end.
Q100. Check whether or not a linked list has a loop
To check if a linked list has a loop, we can use the Floyd's cycle-finding algorithm.
Use two pointers, one moving at twice the speed of the other
If there is a loop, the fast pointer will eventually catch up with the slow pointer
If the fast pointer reaches the end of the list, there is no loop
Top HR Questions asked in null
Interview Process at null
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month