Front end Developer
1000+ Front end Developer Interview Questions and Answers

Asked in Josh Technology Group

Q. Non-Decreasing Array Problem Statement
Given an integer array ARR
of size N
, determine if it can be transformed into a non-decreasing array by modifying at most one element.
An array is defined as non-decreasin...read more
The solution checks if an integer array can become non-decreasing by modifying at most one element.
Iterate through the array and check if there are more than one decreasing pairs of elements.
If there are more than one decreasing pairs, return false.
If there is only one decreasing pair, check if modifying one of the elements can make the array non-decreasing.
If modifying the element at index i-1 or i can make the array non-decreasing, return true.
Otherwise, return false.

Asked in Josh Technology Group

Q. Find Unique Element in Array
You have been provided an integer array/list ARR
of size N
. Here, N
is equivalent to 2M + 1
where each test case has M
numbers appearing twice and one number appearing exactly once....read more
The task is to find the unique number in an array where all other numbers occur twice.
The array size is given by N = 2M + 1, where M is the number of elements occurring twice.
Loop through the array and use a hashmap to count the occurrences of each number.
Return the number with a count of 1, as it is the unique number.
Front end Developer Interview Questions and Answers for Freshers

Asked in Amazon

Q. Dijkstra's Shortest Path Problem Statement
You are given an undirected graph with V
vertices (numbered from 0 to V-1) and E
edges. Each edge connects two nodes u
and v
and has an associated weight representing ...read more
The question is about finding the shortest path distance from a source node to all vertices in an undirected graph.
The graph is represented by the number of vertices and edges, followed by the edges and their distances.
The task is to find the shortest path distance from the source node (0) to all other nodes.
If a node is disconnected from the source node, print the maximum positive integer value (2147483647).
Implement the function and return the shortest path distances in asc...read more

Asked in JUSPAY

Q. Encode N-ary Tree to Binary Tree Problem Statement
You are provided with an N-ary tree constituted of 'N' nodes, where node '1' is the head of the tree. Your task is to encode this N-ary tree into a binary tree...read more
The task is to encode an N-ary tree into a binary tree and then decode the binary tree back into the original N-ary tree.
Encode the N-ary tree by representing each node as a binary tree node with its first child as the left child and subsequent children as the right child.
To decode the binary tree, traverse the binary tree and for each node, create a new N-ary tree node with its left child as the first child and subsequent right children as siblings.
Use a level order traversa...read more

Asked in Amazon

Q. Check If Linked List Is Palindrome
Given a singly linked list of integers, determine if the linked list is a palindrome.
Explanation:
A linked list is considered a palindrome if it reads the same forwards and b...read more
Check if a given singly linked list of integers is a palindrome or not.
Create a function to reverse the linked list.
Use two pointers to find the middle of the linked list.
Compare the first half of the linked list with the reversed second half to determine if it's a palindrome.

Asked in JUSPAY

Q. Path Existence in Directed Graph
Given a directed and unweighted graph characterized by vertices 'V' and edges 'E', determine if a path exists from a specified 'source' vertex to a 'destination' vertex. The edg...read more
The task is to check if there exists a path from a given source vertex to a destination vertex in a directed and unweighted graph.
Read the number of test cases.
For each test case, read the number of vertices and edges.
Read the edges of the graph.
Read the source and destination vertices.
Implement a graph traversal algorithm (e.g., BFS or DFS) to check if a path exists from the source to the destination.
Print 'true' if a path exists, otherwise print 'false'.
Front end Developer Jobs




Asked in Amazon

Q. Sort Linked List Based on Actual Values
You are given a Singly Linked List of integers that is initially sorted according to the absolute values of its elements. Your task is to sort this Linked List based on t...read more
The task is to sort a singly linked list based on actual values instead of absolute values.
Traverse the linked list and store the values in an array
Sort the array using any sorting algorithm
Create a new linked list using the sorted array
Return the new linked list

Asked in Amdocs

Q. Sort Array Problem Statement
Given an array consisting of 'N' positive integers where each integer is either 0, 1, or 2, your task is to sort the given array in non-decreasing order.
Input:
Each input starts wi...read more
Sort an array of positive integers (0, 1, 2) in non-decreasing order.
Use counting sort algorithm to sort the array efficiently.
Count the occurrences of 0s, 1s, and 2s in the array.
Update the array with the counts of each element in non-decreasing order.
Share interview questions and help millions of jobseekers 🌟

Asked in Accenture

Q. How can you redirect to the login page using React Router if a user is not logged in and attempts to access another page via URL?
Use React Router's Redirect component to redirect to login page if user is not logged in.
Create a PrivateRoute component that checks if user is logged in
If user is not logged in, redirect to login page using Redirect component
Wrap the routes that require authentication with PrivateRoute component

Asked in PharmEasy

Q. Reverse Words in a String
Given a string STR
consisting of words separated by spaces, reverse the order of words in STR
.
Note:
A word is defined as a sequence of non-space characters. Attempt to perform the ope...read more
Reverse the order of words in a string without allocating extra space.
Split the string into words using space as delimiter
Reverse the order of the words in the array
Join the words back together with spaces in between

Asked in Oracle

Q. Merge K Sorted Arrays Problem Statement
Given 'K' different arrays that are individually sorted in ascending order, merge all these arrays into a single array that is also sorted in ascending order.
Input
The f...read more
Merge K sorted arrays into a single sorted array.
Create a min heap to store the first element of each array along with the array index.
Pop the top element from the heap, add it to the result array, and push the next element from the same array back to the heap.
Repeat the process until all elements are processed.
Time complexity: O(N log K) where N is the total number of elements and K is the number of arrays.

Asked in TCS

Q. Allocate Books Problem Statement
Given an array of integers arr
, where arr[i]
represents the number of pages in the i-th
book, and an integer m
representing the number of students, allocate all the books in suc...read more
Allocate books to students in a way that minimizes the maximum number of pages assigned to a student.
Iterate through possible allocations and calculate the maximum pages assigned to a student.
Find the minimum of these maximums to get the optimal allocation.
Return the minimum pages allocated in each test case, or -1 if not possible.

Asked in Josh Technology Group

Diameter of a Binary Tree Problem Statement
Given a binary tree, return the length of its diameter. The diameter of a binary tree is defined as the length of the longest path between any two nodes in the tree.
The diameter of a binary tree is the length of the longest path between any two end nodes in the tree.
The diameter of a binary tree can be calculated by finding the maximum of the following three values: 1) the diameter of the left subtree, 2) the diameter of the right subtree, and 3) the longest path that passes through the root node.
To find the diameter of a binary tree, we can use a recursive approach. We calculate the height of the left and right subtrees, and then calcul...read more

Asked in Accenture

Q. How can you only accept JPG and PNG files using HTML5?
Use the accept attribute in the input tag to only allow jpg and png files.
Add accept attribute to input tag with 'image/jpeg, image/png' value
This will restrict file selection to only jpg and png files

Asked in Wipro

Q. Segregate Odd-Even Problem Statement
In a wedding ceremony at NinjaLand, attendees are blindfolded. People from the bride’s side hold odd numbers, while people from the groom’s side hold even numbers. For the g...read more
Rearrange a linked list such that odd numbers appear before even numbers while preserving the order.
Create two separate linked lists for odd and even numbers
Traverse the original list and append nodes to respective odd/even lists
Combine the odd and even lists while maintaining the order
Return the rearranged linked list

Asked in Samsung

Q. Triplets with Given Sum Problem
Given an array or list ARR
consisting of N
integers, your task is to identify all distinct triplets within the array that sum up to a specified number K
.
Explanation:
A triplet i...read more
The task is to identify all distinct triplets within an array that sum up to a specified number.
Iterate through the array and use nested loops to find all possible triplets.
Check if the sum of the triplet equals the specified number.
Print the valid triplets or return -1 if no such triplet exists.

Asked in PayPal

Q. Find Magic Index in Sorted Array
Given a sorted array A consisting of N integers, your task is to find the magic index in the given array, where the magic index is defined as an index i such that A[i] = i.
Exam...read more
Find the magic index in a sorted array where A[i] = i.
Iterate through the array and check if A[i] = i for each index i.
Since the array is sorted, you can optimize the search using binary search.
Return the index if found, else return -1.

Asked in greytHR

Q. Most Frequent Non-Banned Word Problem Statement
Given a paragraph consisting of letters in both lowercase and uppercase, spaces, and punctuation, along with a list of banned words, your task is to find the most...read more
Find the most frequent word in a paragraph that is not in a list of banned words.
Split the paragraph into words and convert them to uppercase for case-insensitivity.
Count the frequency of each word, excluding banned words.
Return the word with the highest frequency in uppercase.

Asked in DE Shaw

Q. Chocolate Distribution Problem
You are given an array/list CHOCOLATES
of size 'N', where each element represents the number of chocolates in a packet. Your task is to distribute these chocolates among 'M' stude...read more
Distribute chocolates among students to minimize difference between largest and smallest packets.
Sort the array of chocolates packets
Calculate the minimum possible difference between the maximum and minimum number of chocolates in packets distributed to students
Return the minimum possible difference

Asked in SAP

Q. Remove Duplicates Problem Statement
You are given an array of integers. The task is to remove all duplicate elements and return the array while maintaining the order in which the elements were provided.
Example...read more
Remove duplicates from an array of integers while maintaining order.
Iterate through the array and add elements to a new array if they are not already present
Use a hash set to keep track of unique elements
Return the new array with unique elements in the same order as the original array

Asked in Josh Technology Group

Q. Rotate Linked List Problem Statement
Given a linked list consisting of 'N' nodes and an integer 'K', your task is to rotate the linked list by 'K' positions in a clockwise direction.
Example:
Input:
Linked List...read more
Rotate a linked list by K positions in a clockwise direction.
Traverse the linked list to find the length and the last node.
Connect the last node to the head to form a circular linked list.
Find the new head by moving (length - K) steps from the last node.
Break the circular link and update the head and tail pointers.
Return the new head of the rotated linked list.

Asked in Amdocs

Q. Swap Two Numbers Problem Statement
Given two integers a
and b
, your task is to swap these numbers and output the swapped values.
Input:
The first line contains a single integer 't', representing the number of t...read more
Swap two numbers 'a' and 'b' and output the swapped values.
Create a temporary variable to store one of the numbers before swapping
Assign the value of 'a' to 'b' and the temporary variable to 'a'
Output the swapped values as 'b' followed by 'a'

Asked in Info Edge

Q. Matching Prefix Problem Statement
Given an integer N
representing the number of strings in an array Arr
composed of lowercase English alphabets, determine a string S
of length N
such that it can be used to dele...read more
Given an array of strings, find the lexicographically smallest string that can be used as a prefix to minimize the total cost of deleting prefixes from the strings.
Iterate through the array to find the common prefix among all strings
Choose the lexicographically smallest common prefix
Delete the common prefix from each string in the array to minimize the total cost

Asked in Amazon

Q. Alien Dictionary Problem Statement
You are provided with a sorted dictionary (by lexical order) in an alien language. Your task is to determine the character order of the alien language from this dictionary. Th...read more
Given a sorted alien dictionary in an array of strings, determine the character order of the alien language.
Iterate through the words in the dictionary to build a graph of character dependencies.
Perform a topological sort on the graph to determine the character order.
Return the character array representing the order of characters in the alien language.

Asked in Amdocs

Q. Palindrome String Validation
Determine if a given string 'S' is a palindrome, considering only alphanumeric characters and ignoring spaces and symbols.
Note:
The string 'S' should be evaluated in a case-insensi...read more
Validate if a given string is a palindrome after removing special characters, spaces, and converting to lowercase.
Remove special characters and spaces from the input string
Convert the string to lowercase
Check if the modified string is equal to its reverse to determine if it's a palindrome

Asked in Amazon

Q. 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 a given capacity.
Implement a doubly linked list to keep track of the order of keys based on their recent usage.
Use a hashmap to store key-value pairs for quick access and updates.
When capacity is reached, evict the least recently used item before inserting a new one.
Update the order of keys in the linked list whenever a key is accessed or updated.

Asked in Analytic Edge

Q. Postorder Successor Problem Statement
You are provided with a binary tree consisting of 'N' distinct nodes and an integer 'M'. Your task is to find and return the postorder successor of 'M'.
Note:
The postorder...read more
Find the postorder successor of a node in a binary tree.
Traverse the binary tree in postorder to get the sequence.
Find the index of the node 'M' in the postorder sequence.
Return the element at the next index as the postorder successor.
If 'M' is the last element in the sequence, return -1 as there is no successor.

Asked in OodlesTechnologies

The return type of getElementsByClassName method in JavaScript is an array of elements.
The method returns an array of elements that have a specified class name.
The elements are returned in the order they appear in the document.
If no elements are found with the specified class name, an empty array is returned.

Asked in Red Hat

Q. Jumping Numbers Problem Statement
Given a positive integer N
, your goal is to find all the Jumping Numbers that are smaller than or equal to N
.
A Jumping Number is one where every adjacent digit has an absolute...read more
Find all Jumping Numbers smaller than or equal to a given positive integer N.
Iterate through numbers from 0 to N and check if each number is a Jumping Number.
For each number, check if the absolute difference between adjacent digits is 1.
Include all single-digit numbers as Jumping Numbers.
Output the list of Jumping Numbers that are smaller than or equal to N.

Asked in Gainsight

Calling a function using the new keyword creates a new instance of the function's constructor.
Creates a new empty object
Binds 'this' to the new object
Adds a property to the new object called '__proto__' which points to the constructor function's prototype object
Returns the new object
Interview Questions of Similar Designations
Interview Experiences of Popular Companies





Top Interview Questions for Front end Developer Related Skills



Reviews
Interviews
Salaries
Users

