
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
Found 26504 Articles for Server Side Programming

290 Views
Suppose we have an array of integers; we have to sort them in ascending order. So if the array is like [5, 2, 3, 1], then the result will be [1, 2, 3, 5]To solve this, we will follow these steps −Make one method called partition, this will take array, low and highset pivot := lowfor i in range low to high – 1if nums[i] < nums[high], then swap(nums[i] and nums[pivot]), increase pivot by 1swap nums[pivot] and nums[high]Define a method called sortArr(), this will take array, low and highif low >= high, then returnpartitionIndex := partition(nums, low, high)sortArr(nums, low, partitionIndex ... Read More

608 Views
Suppose in an election, the i-th vote was cast for persons[i] at time times[i]. Now, we have to implement the following query function: TopVotedCandidate.q(int t) this will find the number of the person that was leading the election at time t. Votes cast at time t will count towards our query. If there is a tie, the most recent vote (among tied candidates) wins.So if we initialize this with TopVotedCandidate([0, 1, 1, 0, 0, 1, 0], [0, 5, 10, 15, 20, 25, 30]), then call q() like: q(3), q(12), q(25), q(15), q(24), q(8), then the result will be [0, 1, ... Read More

262 Views
Suppose we have an array A of integers, for each integer A[i] we have to choose either x = -K or x = K, and add x to A[i] (only once). So after this process, we have some array B. We have to find the smallest possible difference between the maximum value of B and the minimum value of B. So if the input is A = [0, 10], K = 2, then the output will be 6, as B = [2, 8].To solve this, we will follow these steps −set ret := 0, n := size of array Asort ... Read More

315 Views
Suppose we have to create an iterator that iterates through a run-length encoded sequence. Here the iterator is initialized by calling RLEIterator(int[] A), where A is a run-length encoding of a sequence. So we can say that for all even i, A[i] tells us the number of times that the non-negative integer value A[i+1] is repeated in the sequence. Here iterator supports one function −next(int n): This function exhausts the next n elements (n >= 1) and returns the last element exhausted in this way. So if there is no element left to exhaust, next returns -1 instead.Suppose we start ... Read More

223 Views
Suppose we have a set of N people (they are numbered 1, 2, ..., N), we would like to split everyone into two subgroups of any size. Now each person may dislike some other people, and they should not go into the same group. So, if dislikes[i] = [a, b], it indicates that it is not allowed to put the people numbered a and b into the same group. We have to find if it is possible to split everyone into two groups in this way.So if the input is like N = 4 and dislike = [[1, 2], [1, ... Read More

417 Views
Suppose we have a 2 dimensional grid with R rows and C columns, we start from (r0, c0) facing east. Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the grid is at the last row and column. We will walk in a clockwise spiral shape to visit every position in this grid. When we are at the outside the boundary of the grid, we continue our walk outside the grid (but may return to the grid boundary later.). We have to find a list of coordinates representing the positions ... Read More

703 Views
Suppose we have an array called people. Now the i-th person has weight people[i], and each boat can carry a maximum weight of limit. If each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at most limit. We have to find the minimum number of boats to carry every given person. So if the input is like [3,2,1,2], and limit is 3, then we need three boats. [(1,2), (2), (3)].To solve this, we will follow these steps −sort the people arrayi := 0, j := size of people array – 1, ret := 0while i

574 Views
Suppose we have two players Alex and Lee they play a game with piles of stones. There are an even number of piles that are arranged in a row, and each pile has some number of stones piles[i]. The objective of the game is to end with the most stones. When the total number of stones is odd, there are no ties. Alex and Lee take turns, with Alex starting first. In each turn, a player takes the entire pile of stones from either the beginning or the end of the row. This will be continued until there are no ... Read More

445 Views
Suppose we have N piles of bananas, the i-th pile has piles[i] bananas. Here the guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed is K. Each hour, she takes some pile of bananas, and eats K bananas from that pile. If the pile has less than K bananas, then she consumes all of them instead, and won't eat any more bananas during this hour. Consider Koko likes to eat slowly, but still wants to finish eating all the bananas before the guards come back. We have to find the minimum integer ... Read More