Minimum Absolute Difference in an Array
Given an array of integers, find and print the minimum absolute difference between any two elements in the array. For example, Input: -59 -36 -13 1 -53 -92 -2 -96 -54 75 Output: 1...
Given an array of integers, find and print the minimum absolute difference between any two elements in the array. For example, Input: -59 -36 -13 1 -53 -92 -2 -96 -54 75 Output: 1...
Different ways to track the max value while iterating over different values We can use if, ternary operator or Math.max function as shown below. if (val > max) { max = val...
Given the following string extract the number ‘Buy for $199.99’ // 199.99 ‘Gas Price $2.304 per gallon’ // 2.304 We can solve this using slice and, parseFloat(). slice returns the string from the starting...
Recursive : To delete all the nodes, you will have to visit all the nodes. There are three ways to traverse the binary tree : Post order Pre order In order. To delete all...
Problem : Given a JSON data structure with key representing age and value representing the number of people with that age. For example, { 25: 55, 26: 45, 27: 10, 28: 20, 30: 1,...