Front end Developer

filter-iconFilter interviews by

800+ Front end Developer Interview Questions and Answers

Updated 24 Feb 2025

Popular Companies

search-icon

Q1. 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

Ans.

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.

Q2. 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

Ans.

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

illustration image

Q3. 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

Ans.

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

Q4. 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

Ans.

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

Are these interview questions helpful?

Q5. 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

Ans.

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

Q6. 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

Ans.

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'.

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q7. 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

Ans.

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.

Q8. 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
Ans.

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.

Front end Developer Jobs

Frontend Developer 3-8 years
IBM India Pvt. Limited
4.0
Bangalore / Bengaluru
Frontend Developer 3-8 years
IBM India Pvt. Limited
4.0
Bangalore / Bengaluru
Frontend Developer 3-6 years
IBM India Pvt. Limited
4.0
Bangalore / Bengaluru

Q9. How to redirect to login page through React Router if the user has not logged in and trying to go to another page through URL.

Ans.

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

Q10. ...read more

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.

Ans.

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

Q11. 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

Ans.

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

Q12. 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

Ans.

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.

Q13. 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
Ans.

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.

Q14. 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

Ans.

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

Q15. How can you only accept jpg and png files using HTML5.

Ans.

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

Q16. 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

Ans.

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.

Q17. 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

Ans.

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.

Frequently asked in,

Q18. 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

Ans.

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.

Q19. 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

Ans.

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

Frequently asked in,

Q20. 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

Ans.

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

Q21. 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
Ans.

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.

Q22. 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
Ans.

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'

Q23. 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

Ans.

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

Q24. 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

Ans.

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.

Q25. 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
Ans.

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

Q26. 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

Ans.

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.

Frequently asked in,

Q27. 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

Ans.

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.

Q28. What is the return type of the getElementsByClassName method in JavaScript?
Ans.

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.

Q29. 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

Ans.

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.

Q30. What happens when you call a function using the new keyword?
Ans.

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

Q31. How to center align a div in just one line in css.

Ans.

Use flexbox to center align a div in just one line in CSS.

  • Set the parent container's display property to flex.

  • Use the justify-content property with the value 'center' to horizontally center the div.

  • Use the align-items property with the value 'center' to vertically center the div.

Q32. String Palindrome Verification

Given a string, your task is to determine if it is a palindrome considering only alphanumeric characters.

Input:

The input is a single string without any leading or trailing space...read more
Ans.

Check if a given string is a palindrome considering only alphanumeric characters.

  • Remove non-alphanumeric characters from the input string.

  • Compare the string with its reverse to check for palindrome.

  • Handle edge cases like empty string or single character input.

  • Use two pointers approach for efficient comparison.

Q33. Priority CPU Scheduling Problem

Given 'N' processes with their “burst times”, where the “arrival time” for all processes is ‘0’, and the ‘priority’ of each process, your task is to compute the “waiting time” an...read more

Ans.

Implement Priority CPU Scheduling algorithm to compute waiting time and turn-around time for processes.

  • Implement a function that takes in burst times, priorities, and number of processes as input

  • Sort the processes based on priority, with lower process ID as tiebreaker

  • Calculate waiting time and turn-around time for each process based on the scheduling algorithm

Q34. Is Javascript single thread or multithread?

Ans.

Javascript is single-threaded.

  • Javascript runs on a single thread called the event loop.

  • This means that it can only execute one task at a time.

  • However, it can delegate tasks to other threads using web workers.

  • This allows for parallel processing without blocking the main thread.

Q35. implement a calculator class which does this cal.add(2).sub(3).mul(4).delay(2000).add(4) etc

Ans.

Implement a calculator class with chaining methods and delay function.

  • Create a Calculator class with add, sub, mul methods that return the instance of the class.

  • Implement a delay method that uses setTimeout and returns the instance of the class.

  • Use a queue to store the operations and execute them in order after the delay.

  • Return the result of the operations when the equals method is called.

Q36. What are the differences between a Component and a Directive in Angular?
Ans.

Components are building blocks of Angular applications, while directives are used to add behavior to DOM elements.

  • Components have a template, styles, and behavior encapsulated together, while directives are used to manipulate the behavior of existing DOM elements.

  • Components are typically used to create reusable UI elements, while directives are used to add custom behavior to existing elements.

  • Components can have their own view encapsulation, while directives do not have their...read more

Q37. How can you import all exports of a file as an object in JavaScript?
Ans.

You can import all exports of a file as an object in JavaScript using the 'import * as' syntax.

  • Use the 'import * as' syntax followed by the object name and 'from' keyword to import all exports of a file as an object.

  • For example: import * as myExports from './myFile.js';

  • You can then access the exports using dot notation, like myExports.myFunction().

Q38. What are the data types in JavaScript?
Ans.

JavaScript data types include string, number, boolean, object, function, undefined, and null.

  • String: 'hello'

  • Number: 42

  • Boolean: true or false

  • Object: { key: 'value' }

  • Function: function() { }

  • Undefined: undefined

  • Null: null

Q39. Remove duplicate elements from an Array

Ans.

Remove duplicate elements from an Array

  • Use the Set object to remove duplicate elements

  • Convert the Set back to an array using the spread operator

  • If the array contains objects, use a custom comparison function

Q40. Can you explain the Async/Await function in JavaScript?
Ans.

Async/Await is a feature in JavaScript that allows for easier handling of asynchronous code.

  • Async/Await is built on top of Promises and provides a more readable and concise way to work with asynchronous code.

  • The 'async' keyword is used to define a function as asynchronous, allowing the use of 'await' inside it to pause execution until a Promise is settled.

  • Using Async/Await can help avoid callback hell and make code more maintainable and easier to understand.

  • Example: async fun...read more

Q41. What is the difference between inheritance and generalization in the context of database management systems?
Ans.

Inheritance is a relationship between a superclass and subclass, while generalization is a relationship between entities with common characteristics.

  • Inheritance involves a parent-child relationship where the child class inherits attributes and methods from the parent class.

  • Generalization involves grouping entities with common attributes into a higher-level entity.

  • Inheritance is a specific form of generalization in object-oriented programming.

  • Example: In a database, a 'Car' en...read more

Q42. What is css media queries and difference between min and max

Ans.

CSS media queries are used to apply different styles based on device characteristics. Min and max define the range of values.

  • Media queries allow for responsive design by adapting to different screen sizes and orientations

  • Min-width and max-width are commonly used to define the range of screen sizes

  • Min-device-width and max-device-width are used to target specific device characteristics

  • Other media query features include min-height, max-height, orientation, and resolution

Q43. Why javascript is Dynamic language? Ans: The type of variable is dynamically changed based on the its current value. that is the reason the javascript is treated as as dynamic language.

Ans.

JavaScript is considered a dynamic language because variables can change types based on their current value.

  • Variables in JavaScript can hold different types of values at different times

  • The type of a variable is determined at runtime, not at compile time

  • Dynamic typing allows for flexibility and ease of use in JavaScript programming

  • Example: a variable can start as a number and then be reassigned as a string

Q44. What is the difference between 'var' and 'let' in JavaScript?
Ans.

var is function scoped while let is block scoped in JavaScript.

  • var is function scoped, meaning it is accessible throughout the function it is declared in.

  • let is block scoped, meaning it is only accessible within the block it is declared in.

  • Using var can lead to variable hoisting issues, while let avoids this problem.

  • Example: var x = 10; function test() { var x = 20; console.log(x); } test(); // Output: 20

Q45. how would you optimize the api call on input change(Debouncing)

Ans.

Debounce the API call on input change to optimize performance.

  • Implement a debounce function to delay the API call until the user has finished typing.

  • Set a time interval for the debounce function to wait before making the API call.

  • Cancel the previous API call if a new input change occurs before the time interval is up.

  • Use a loading spinner to indicate to the user that the API call is in progress.

  • Consider using a caching mechanism to store the API response for future use.

Q46. Is functional components and class components both are same or not?

Ans.

Functional components and class components are not the same in React. Functional components are simpler and more lightweight, while class components have additional features like state and lifecycle methods.

  • Functional components are stateless and are just JavaScript functions that return JSX.

  • Class components have access to state and lifecycle methods like componentDidMount and componentDidUpdate.

  • Functional components are easier to read and test, while class components can be ...read more

Q47. what is jquery? 2.explain architecture of your project.

Ans.

jQuery is a fast, small, and feature-rich JavaScript library.

  • jQuery simplifies HTML document traversing, event handling, and animating.

  • It provides a set of methods for AJAX interactions and DOM manipulation.

  • jQuery is cross-platform and supports a wide range of browsers.

  • It has a large community and a vast number of plugins available.

  • Project architecture depends on the specific project and its requirements.

Q48. Can you describe the process you followed to build a front-end project from scratch?
Ans.

The process of building a front-end project involves planning, designing, coding, testing, and deploying.

  • Gather requirements and create a project plan

  • Design the user interface using tools like Figma or Sketch

  • Code the front-end using HTML, CSS, and JavaScript

  • Test the project for bugs and usability

  • Deploy the project to a web server or hosting platform

Q49. How will you develop an application which shows all airports in the country in a map. User needs to login and report any incidents happened in a particular airport

Ans.

Develop an app to show all airports in a country on a map and allow users to report incidents after logging in.

  • Use a map API like Google Maps or Mapbox to display all airports in the country

  • Implement a login system for users to report incidents

  • Create a form for users to report incidents with fields like airport name, incident type, and description

  • Store incident reports in a database for future reference and analysis

Q50. How does one share data between components in Angular?
Ans.

Data can be shared between components in Angular using services, input/output properties, and observables.

  • Use services to create a shared data service that can be injected into multiple components

  • Use input/output properties to pass data from parent to child components

  • Use observables to create a data stream that can be subscribed to by multiple components

1
2
3
4
5
6
7
Next
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.4k Interviews
3.8
 • 8.1k Interviews
3.6
 • 7.5k Interviews
3.7
 • 5.6k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.7k Interviews
3.5
 • 3.8k Interviews
4.0
 • 2.3k Interviews
2.4
 • 13 Interviews
View all

Calculate your in-hand salary

Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary

Recently Viewed
DESIGNATION
Pyspark Developer
25 interviews
DESIGNATION
DESIGNATION
DESIGNATION
DESIGNATION
DESIGNATION
INTERVIEWS
Alcazar Capital
No Interviews
INTERVIEWS
Makeover Fashion Inc
No Interviews
INTERVIEWS
More Mega Store
No Interviews
DESIGNATION
Front end Developer Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter