React JS Question Bank
React JS Question Bank
87. How can you count the number of occurrences of a particular character in a JavaScript String,
and what are some different approaches that can be used to achieve this?
88. What is a possible approach to find the most frequently occurring character in a JavaScript
String, and how can you implement this solution in JavaScript programming?
89. What is an approach to add the individual digits of a given integer in JavaScript programming,
and how can you implement this solution to calculate the sum of digits for an integer such as
567 and return the result of 9?
90. Write a JavaScript program to find the largest subarray in an integer array that has a sum of 0.
Can you explain your approach to solving this problem and provide a step-by-step explanation
of your code? How does your program handle edge cases, such as when there is no subarray
with a sum of 0 or when the input array is empty?
{ 3, 4, -7 }
{ 4, -7, 3 }
{ -7, 3, 1, 3 }
{ 3, 1, -4 }
{ 3, 1, 3, 1, -4, -2, -2 }
{ 3, 4, -7, 3, 1, 3, 1, -4, -2, -2 } // This should be the output
91. Can you provide a program in JavaScript that finds all the subarrays in an array whose sum is
zero? How does your implementation work? Can you explain the time and space complexity of
your solution? Are there any optimizations that can be made to improve the efficiency of your
program?
92. Write a JavaScript program to find the sum of all the numbers in a given string. For example, if
the input string is "1ab2d4hj6", the program should output the sum of numbers in the string,
which is 13.
The program should take a string as input from the user and use regular expressions to extract
all the numbers from the string. It should then iterate over the extracted numbers and add them
up to get the final sum. If there are no numbers in the string, the program should output 0.
93. Write a JavaScript program that takes two strings as input and finds the number of occurrences
of the second string in the first string.
Example:
Input:
String 1: "hello world"
String 2: "l"
Output:
Number of occurrences of "l" in "hello world" is 3
94. Write a JavaScript program to find the sum of all the numbers in a given string. Your program
should take a string as input from the user and then find all the numbers in the string. It should
then add up all the numbers and print the sum to the console.
The string should be read from the console using the Scanner class.
Your program should use regular expressions to find all the numbers in the string.
The sum of the numbers should be calculated using a loop.
If there are no numbers in the string, your program should print a message saying so.
Example:
Input: "Hello 123 world 456"
Output: 579
Write test cases on the same program by using the assertion method in Junit.
95. Write a JavaScript program to find the sum of all the numerical digits in a given string s1. The
string can contain alphabets and digits in any order, but the digits are guaranteed to be
consecutive. Your program should output the total sum of all the digits in the string.
For example, given the string s1 = "abc4ui78fg95", the program should output sum = 177, since
the digits in the string are 4, 7, 8, 9, and 5, and their sum is 4 + 7 + 8 + 9 + 5 = 33.
96. Given a matrix of integers, write a program to modify the matrix such that if any element of the
matrix is 0, then the entire row and column of that element should be set to 0. Implement this
program using JavaScript.
Check for the presence of 0 in the matrix and record the positions of the 0 elements.
Modify the matrix by setting the entire row and column to 0 if any element in the row or column
contains a 0.
The program should return the modified matrix as output.
{ 1, 2, 3 }
{ 4, 0, 6 }
{ 7, 8, 9 }
{ 1, 0, 3 }
{ 0, 0, 0 }
{ 7, 0, 9 }
Example input:
Expected output:
Constraints:
newarr = [1,8,3,6,5,4,7,2]
102. Given an unsorted array a = [3,1,5,2,7], find alternate elements "3,5,7", reverse them "7,5,3"
and place them in the original array
Expected result [7,1,5,2,3]
103. Find second largest number [3,1,5,2,7]
104. Out of given 3 arrays with n number of elements, find out the common element(s) for all 3
arrays.
105. From a given array, make n elements rotate.
eg.
Output:
2=3
1=1
3=3
4=5
6=5
5=5
7=2
8=1
107. Print the right diagonal of the matrix
Input:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
4 7 10 13
108. String= "abaade", search for a character "a" in the given string and return its occurrence.
109. How will you remove duplicate elements from an array?
110. Can you provide a sample program in JavaScript that takes an array as input and generates
a new array containing only unique elements, and explain how it works in detail?
111. How can you extract all the keys from a nested object in JavaScript, given an object 'object =
{id:1 , address : {'primaryAddress':'abc'} }', and return an array of keys as
'['id','address','primaryAddress']'? Also, how would you remove duplicates from an array
'[1,1,2,2,3,4,4,5]' in JavaScript?
112. Write a JavaScript function that takes an array of numbers as input and returns a new array
where each element at index i is the sum of all the elements in the input array up to index i. For
example, if the input array is [1, 2, 3, 4], the output should be [1, 3, 6, 10].
113. Given an array of strings, write a JavaScript function that returns the longest string from the
array. For example, if the input array is ["i am in pune", "i am in hyderabad", "location"], the output
should be "i am in hyderabad".
114. Write a program that finds the longest string in an array and returns the number of words in
that string. The input array will be of the form:
const sentences = ["alice and bob love leetcode", "i think so too", "this is great thanks very
much"];
The program should output the longest sentence along with the number of words in that
sentence.
Additionally, write a program that takes an input array of numbers and returns an output array
where the first element of the output array is the first element from the input array, the second
element of the output array is the sum of the first and second elements from the input array, the
third element of the output array is the sum of the previous element (1 + 2 = 3) and the next
element (3 + 3 = 6), and the fourth element is the sum of the previous element (3 + 3 = 6) and
the next element (6 + 4 = 10). The input array will be of the form:
1. Tell me about a project you worked on where you had to communicate technical information to a
non-technical audience.
2. How do you prioritize and manage your workload?
3. Can you describe a time when you had to work with a difficult team member?
4. How do you handle criticism of your code or work?
5. Can you describe a time when you had to work under pressure to meet a deadline?
6. How do you ensure that your code is maintainable and scalable?
7. Tell me about a time when you had to learn a new technology or programming language quickly.
8. How do you keep up-to-date with the latest developments in software development?
9. Can you describe a time when you had to work on a project that required collaboration with
multiple teams?
10. How do you approach problem-solving in your work?
11. Can you give an example of how you have applied creativity in your work as a software
developer?
12. Can you describe a time when you had to work on a project with a tight budget?
13. How do you ensure that your code is properly documented?
14. Tell me about a time when you had to work with a client or end-user to understand their needs
and requirements.
15. How do you approach debugging complex software issues?
16. Can you describe a time when you had to make a trade-off between code quality and speed of
delivery?
17. How do you collaborate with other developers on a project?
18. Tell me about a time when you had to mentor or train other developers.
19. Can you describe a time when you had to persuade a team to adopt a new technology or
approach?
20. How do you approach testing and ensuring the quality of your code?