ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a number, num, as the second argument.The numbers in the array are in the range [1, 13], limits inclusive, representing the 1-based index of playing cards.Our function should determine whether there exists a way to rearrange the cards into groups so that each group is size num, and consists of num consecutive cards.For example, if the input to the function isInputconst arr = [1, 4, 3, 2]; const num = 2;Outputconst output = 2;Output ExplanationBecause the cards can be ... Read More
Centrally Peaked ArrayWe call an array arr a centrally peaked array if the following properties hold −arr.length >= 3There exists some i with 0 < i < arr.length - 1 such thatarr[0] < arr[1] < ... arr[i-1] < arr[i]arr[i] > arr[i+1] > ... > arr[arr.length - 1]ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.The input array is a centrally peaked array. Our function is supposed to return the peak index of this centrally peaked array.For example, if the input to the function isInputconst arr = ... Read More
ProblemWe are required to write a JavaScript function that takes in a balanced square bracket string, str, as the first and the only argument.Our function should compute and return the score of the string based on the following rule −[] has score 1AB has a score A + B, where A and B are balanced bracket strings.[A] has score 2 * A, where A is a balanced bracket string.For example, if the input to the function isInputconst str = '[][]';Outputconst output = 2;ExampleFollowing is the code −const findScore = (str = '') => { const arr = [] ... Read More
In this post, we will understand the difference between PLA and PAL −PLAIt stands for Programmable Logic Array.Its speed is lesser in comparison to PAL.It is highly complex.It is expensive.It is not available easily.It is used less in comparison to PAL.PALIt stands for Programmable Array Logic.It has a higher speed in comparison to PLA.It is less complex.It is inexpensive.It is more readily available in comparison to PLA.It is used more in comparison to PLA.
In this post, we will understand the difference between SATA and PATA −PATAIt stands for Parallel Advanced Technology Attachment.It is a 40 pin connector.It is expensive.The speed of data transfer is low.It consumes more power.The size of the cable is big.It doesn’t come with hot swapping feature.External hard drives can’t be used with PATA.SATAIt stands for Serial Advanced Technology Attachment.It is a 7 pin connector.It is cheap.The speed of data transfer is high.It consumes less power.The size of the cable is small.It comes with the hot swapping feature.External hard drives can be used with SATA.Read More
In this post, we will understand the difference between DLP and LCD projector −DLP Projector (Digital Light Processing)It is a type of projector that uses a digital micro mirror device.One of the chip has a reflective surface that contains thousands of tiny mirrors that are coordinated with a light source.This helps reflect the digital imagery on to any surface.It provides smooth video.The pixels are less visible.It is more film-like, as on HDTV.It shows the rainbow effect.The intensity of black is amazing.It is portable since it is small and light in weight.The light source could be a standard lamp or an ... Read More
In this post, we will understand the difference between NC and CNC −NC (Numerical Control)It stands for Numerical Control.The input mechanism is punched tapes and punched cards.The modification in the machine programs can be done by changing the information on punched cards.The operational parameters can’t be changed.There is no memory to store instructions in them.It is less expensive.It requires very less maintenance.It is moderately accurate.The operators using this need to be highly skilled.It is not very flexible.It consumes more time.CNC (Computer Numerical Control)It stands for Computer Numerical Control.The input mechanism is that the program is fed data with the help ... Read More
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.Let us consider the following situation:A shopkeeper sells a single commodity which costs exactly ₹5. Some customers are standing in a queue and will purchase exactly one unit of this commodity each. The customers can provide the shopkeeper with a note of ₹5, ₹10 or ₹20. Considering that the shopkeeper has no money in the beginning and the array represents the notes given by the customers standing in the queue.Our function should determine whether or not the shopkeeper ... Read More
ProblemWe are required to write a JavaScript function that takes in two arrays of numbers, arr1 and arr2, of the same length.Our function should shuffle the elements of the first array, arr1, such that its maximum number of elements are greater than corresponding elements of the array arr2. The function should then return the shuffled array.For example, if the input to the function isInputconst arr1 = [3, 5, 12, 19]; const arr2 = [2, 9, 3, 12];Outputconst output = [3, 12, 5, 19];Output ExplanationBefore shuffling arr1, it had 3 corresponding elements greater than that of arr2, but in the shuffled ... Read More
Fibonacci Sequence:A sequence X_1, X_2, ..., X_n is fibonacci if:n >= 3X_i + X_{i+1} = X_{i+2} for all i + 2 { const map = arr.reduce((acc, num, index) => { acc[num] = index return acc }, {}) const memo = arr.map(() => arr.map(() => 0)) let max = 0 for(let i = 0; i < arr.length; i++) { for(let j = i + 1; j < arr.length; j++) { const a = arr[i] const b = arr[j] const index = map[b - a] if(index < i) { memo[i][j] = memo[index][i] + 1 } max = Math.max(max, memo[i][j]) } } return max > 0 ? max + 2 : 0 }; console.log(longestFibonacci(arr));Output5
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP