Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1798 of 2646
1K+ Views
Suppose there are n bulbs that are initially switched off. We first turn on all the bulbs. Then, we turn off every second bulb. On the third round, we toggle every third bulb (turning on if it's off or turning off if it's on). Similarly, for the i-th round, we toggle every i bulb. For the n-th round, we only toggle the last bulb. So we have to find how many bulbs are on after n rounds. So if the input is 3, then the result will be 1. This is because −At first, the three bulbs are [off, off, ... Read More
350 Views
Suppose we have an integer array arr and a target value target, we have to find the integer value such that when we change all the integers larger than value in the given array will be equal to value, the sum of the array gets as nearest as possible to target. If they are same, then return the minimum such integer. So if the array is like [4, 9, 3] and target is 10, then the output will be 3 as using 3, the array will be [3, 3, 3], so the sum is 9, that is nearest element to ... Read More
306 Views
Suppose we have an array of integers nums and a positive integer k, we have to find whether it's possible to divide this array into sets of k consecutive numbers. So we have to return True if its possible otherwise return False. So if the input is like [1, 2, 3, 3, 4, 4, 5, 6] and k = 4, then output will be true. This is because, we can divide the array such that [1, 2, 3, 4] and [3, 4, 5, 6]To solve this, we will follow these steps −Make one map m, set n := size of ... Read More
465 Views
Suppose we have an integer, that has sequential digits if and only if each digit in the number is one more than the previous digit. We have to find a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. So if the low = 100 and high = 300, then the output will be [123,234]To solve this, we will follow these steps −create one array resfor i in range 1 to nfor j := 1, until j + i – 1
766 Views
Suppose we have an array of integers called nums and an integer k, that is threshold value, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. We have to find the smallest divisor such that the result mentioned above is less than or equal to threshold value k. For example − if nums = [1, 2, 5, 9] and k = 6, then the output will be 5. We can get the sum as (1+2+5+9) = 17 when the divisor is 1. If the divisor is 4, then ... Read More
419 Views
Suppose there are n people whose IDs are in range 0 to n - 1 and each person belongs exactly to one group. We have the array groupSizes of length n. This array is indicating that the group size each person belongs to, we have to find the groups there are and the people's IDs each group includes.Suppose the input is like − [3, 3, 3, 3, 3, 1, 3], then the output is [[5], [0, 1, 2], [3, 4, 6]], Other possible solutions can be [[2, 1, 6], [5], [0, 4, 3]] or [[5], [0, 6, 2], [4, 3, ... Read More
213 Views
Suppose we a binary matrix, of size m x n. We have to count number of square submatrices, with all 1s. So if the matrix is like −011111110111So there will be 15 squares. 10 squares of single ones, 4 squares of four ones, and 1 square with nine ones.To solve this, we will follow these steps −set ans := 0, n := row count and m := column countfor i in range 0 to m – 1ans := ans + matrix[n – 1, i]for i in range 0 to n – 1ans := ans + matrix[i, m – 1]ans := ... Read More
333 Views
Suppose we have two integers tomatoSlices and cheeseSlices. These are the ingredients of different burgers −Jumbo Burger: 4 tomato slices and 1 cheese slice.Small Burger: 2 Tomato slices and 1 cheese slice.We have to find [total_jumbo, total_small] so that the number of tomatoSlices that are left is equal to 0 and the number of cheeseSlices that are left is also 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return []. So if the input is tomatoSlices = 16 and chesseSlices = 7, then the output will be [1, 6]. So this indicates, ... Read More
487 Views
Suppose we have an array nums of integers, we need to find the maximum possible sum of elements of the given array such that it is divisible by three. So if the input is like [3, 6, 5, 1, 8], then the output will be 18, as the subarray is [3, 6, 1, 8], and the sum is 18, that is divisible by 3.To solve this, we will follow these steps −n := size of nums arraycreate one 2d array dp of size (n + 1) x 3set dp[0, 0] := 0, dp[0, 1] := -inf, dp[0, 2] := inffor ... Read More
237 Views
Suppose we have some lists of regions where the first region of each list includes all other regions in that list. basically, if a region X contains another region Y then, X is larger than Y. Also by definition a region X contains itself. So if we have two regions r1 and r2, we have to find the smallest region that contains both of them. So if we have r1, r2 and r3 such that r1 includes r3, it is guaranteed there is no r2 such that r2 includes r3. So if the input is like [["Earth", "North America", "South ... Read More