- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 8894 Articles for Front End Technology
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
249 Views
ProblemWe are required to implement a MapSum class with insert, and sum methods. For the method insert, we'll be given a pair of (string, integer). The string represents the key and the integer represents the value. If the key already existed, then the original key-value pair will be overridden to the new one.For the method sum, we'll be given a string representing the prefix, and we need to return the sum of all the pairs' values whose key starts with the prefix.ExampleFollowing is the code − Live Democlass Node { constructor(val) { this.num = 0 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
58 Views
ProblemWe are required to write a JavaScript function that takes in an array of exactly 4 numbers, arr, as the first argument and a target as the second argument.Our function need to judge whether the numbers in the array arr could operated through *, /, +, -, (, ) to get the value equal to target.For example, if the input to the function isInputconst arr = [5, 3, 2, 1]; const target = 4;Outputconst output = true;Output ExplanationBecause we can achieve 4 like this −(5 - 1) * (3 - 2) = 4ExampleFollowing is the code − Live Democonst arr = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
143 Views
ProblemWe are required to write a JavaScript function that takes in a string, str, as the first and the only argument.Our function may delete at most one character from the string str and we are required to check whether we can make it a palindrome doing so.For example, if the input to the function isInputconst str = 'dr.awkward';Outputconst output = true;Output ExplanationBecause if we delete ‘.’ from the string,ExampleFollowing is the code − Live Democonst str = 'dr.awkward'; const validPalindrome = (str = '') => { const valid = (left, right) => { for (let i = left; i
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
368 Views
ProblemWe are required to write a JavaScript function that takes in a string, time, that represents time in the "HH:MM" form.Our function is supposed to form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.For example, if the input to the function isInputconst time = '19:34';Outputconst output = '19:39';Output ExplanationThe next closest time choosing from digits 1, 9, 3, 4, is 19:39, which occurs 5 minutes later. It is not 19:33, because this occurs 23 hours and 59 minutes later.ExampleFollowing is the code − Live Democonst time = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
52 Views
ProblemWe are required to write a JavaScript function that takes in two strings, str1 and str2, as the first and the second argument.Our function should return the minimum number of times we should repeat string str1 so that string str2 is a substring of it. If it is impossible for str2 to be a substring of a after repeating it, we should return -1For example, if the input to the function isInputconst str1 = 'wxyz'; const str2 = 'yzwxyzwx';Outputconst output = 3;Output ExplanationWe return 3 because by repeating a three times "abcdabcdabcd", b is a substring of it.ExampleFollowing is the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
747 Views
ProblemWe are required to write a JavaScript function that takes in an array, arr, of strings of English lowercase alphabets as the first argument. The second argument to our function is a number, num (num < length of arr).Our function is supposed to return the num most frequent elements in the array arr.The answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first.For example, if the input to the function isInputconst arr = ["the", "day", "is", "sunny", "the", "the", "the", "sunny", "is", "is"]; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
134 Views
ProblemWe are required to write a JavaScript function that takes in an integer, num, as the first and the only argument.Our function should check whether the binary representation of num has alternating bits − namely, if two adjacent bits will always have different values.For example, if the input to the function isInputconst num = 5;Outputconst output = true;Output ExplanationBecause the binary form of 5 is 101 which have alternating bits.ExampleFollowing is the code − Live Democonst num = 5; const isAlternating = (num = 1) => { const binary = num.toString(2); let curr = binary[0]; for(let i = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
105 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.Our function is supposed to find the smallest possible length of a (contiguous) subarray of the array arr, that has the same greatest frequency of any element as the whole array.For example, if the input to the function isInputconst arr = [55, 77, 77, 88, 55];Outputconst output = 2;Output ExplanationThe input array has the greatest frequency for any element of 2 because both elements 55 and 77 appear twice.Of the subarrays that have the greatest frequency as the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
156 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.The array arr, might contain some duplicates. Our function is supposed to sort the array in such a way that the elements that appear for least number of times are placed first followed by elements in increasing frequency.If two elements appear for the same number of times in the array then they should be placed in increasing order.For example, if the input to the function isInputconst arr = [5, 4, 5, 4, 2, 1, 12];Outputconst output = [1, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
54 Views
ProblemWe are required to write a JavaScript function that takes in two strings of English lowercase alphabets, str1 and str2, as the first and the second argument respectively.Our function is supposed to find and return the lowest ASCII sum of deleted characters to make two strings equal.For example, if the input to the function isInputconst str1 = 'sea'; const str2 = 'eat';Outputconst output = 231;Output ExplanationDeleting "s" from "sea" adds the ASCII value of "s" (115) to the sum.Deleting "t" from "eat" adds 116 to the sum.At the end, both strings are equal, and 115 + 116 = 231 is ... Read More