Problem statementGiven lengths of n rods in an array. If any person picks any rod, half of the longest rod (or (max + 1) / 2 ) is assigned and remaining part (max – 1) / 2 is put back. It may be assumed that sufficient number of rods are always available, answer M queries given in an array q[] to find the largest length of rod available for qith person, provided qi is a valid person number starting from 1ExampleInput : a[] = {6, 5, 9, 10, 12} q[] = {1, 3} Output : 12 9 The first ... Read More
Problem statementGiven an array arr[] of N elements (0 ≤ arr[i] ≤ 1000). The task is to find the maximum length of the sub-array that contains only ugly numbers.Ugly numbers are numbers whose only prime factors are 2, 3 or 5.For Example below are the few number from series: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …ExampleIf input array is {1, 2, 7, 9, 120, 810, 374} then answer is 3 as −Longest possible sub-array of ugly number sis {9, 120, 810}AlgorithmTake a unordered_set, and insert all the ugly numbers which are less than 1000 in ... Read More
To handle floating point number precision in JavaScript, use the toPrecision() method. It helps to format a number to a length you can specify.ExampleLive Demo var num = 28.6754; document.write(num.toPrecision(3)); document.write(""+num.toPrecision(2)); document.write(""+num.toPrecision(5)); Output28.7 29 28.675
Problem statementGiven an array, we need to find the maximum height of the triangle which we can form, from the array values such that every (i+1)th level contain more elements with the larger sum from the previous level.ExampleIf input array is {40, 100, 20, 30 } then answer is 2 as −We can have 100 and 20 at the bottom level and either 40 or 30 at the upper level of the pyramidAlgorithmOur solution just lies on the logic that if we have maximum height h possible for our pyramid then ( h * (h + 1) ) / 2 ... Read More
Problem statementThere are N players which are playing a tournament. We need to find the maximum number of games the winner can play. In this tournament, two players are allowed to play against each other only if the difference between games played by them is not more than oneExampleIf There are 3 players then 2 games are required to decide the winner as follows −Game – 1: player 1 vs player 2Game - 2: player 2 vs winner from Game - 1AlgorithmWe can solve this problem by first computing minimum number of players required such that the winner will play ... Read More
Problem statementGiven a string the task is to find the maximum length of the sub-string of that can be arranged into a Palindrome.ExampleIf input string = “5432112356” then answer is 6 as maximum palindrome substring is “321123” and its length is 6AlgorithmIf the length of the sub-string is odd, then it cannot be considered in the final solutions.If the length of the sub-string is even, then it can be a possible solution only if each character in that sub-string occurs even number of times which can be done using the dictionary count. We check if each character occurs even number ... Read More
Problem statementGiven an array arr[]. Find maximum value of prefix sum which is also suffix sum for index i in arr[].ExampleIf input array is −Arr[] = {1, 2, 3, 5, 3, 2, 1} then output is 11 as −Prefix sum = arr[0..3] = 1 + 2 + 3 + 5 = 11 andSuffix sum = arr[3..6] = 5 + 3 + 2 + 1 = 11AlgorithmTraverse the array and store prefix sum for each index in array presum[], in which presum[i] stores sum of subarray arr[0..i]Traverse array again and store suffix sum in another array suffsum[], in which suffsum[i] stores ... Read More
Problem statementGiven a very large array of integers, find maximum within the array using multithreadingExampleIf input array is {10, 14, -10, 8, 25, 46, 85, 1673, 63, 65, 93, 101, 125, 50, 73, 548} thenmaximum element in this array is 1673AlgorithmLet us call array size as total_elementsCreate N threadsEach thread will process (total_elementes/N) array elements and will find maximum element from it.Finally compute the maximum from the maximum value reported by each thread.Example#include #include #include #include #define MAX 10 #define SIZE(arr) (sizeof(arr) / sizeof(arr[0])) typedef struct struct_max { int start; int end; int ... Read More
A favicon is a little icon visible on the web browser tab, just before the page title. It is generally a logo with a smaller size. Here, you can see the favicon, The size of a favicon is 16x16 since it also gets displayed next to the URL of your site in a browser's address bar. It is visible on a users list of bookmarks and easily helps in recognizing the website from a list of websites.To add a favicon icon, you need to create an icon, with size 16x16. Also, some websites provide options to create favicon icon from ... Read More
The CSS color property is used to change the text color of an element. We can specify values as standard color name, rgb(), rgba(), hsl(), hsla() and hexadecimal value.SyntaxThe syntax for CSS color property is as follows −Selector { color: /*value*/ }The following examples illustrate CSS color property −Example Live Demo div { height: 50px; width: 50px; float: right; color: white; background-color: #2f5587; } p { color: rgba(225, 5, 135, 0.7); border: 2px solid #16c618; box-shadow: 0 7px 0 5px hsl(90, 60%, 70%); } Example Heading ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP