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 1791 of 2646
266 Views
Suppose we have a list of words, we may encode it by writing a reference string S and a list of indexes A. So for example, let us consider if the list of words is ["time", "me", "bell"], then we can write it as S = "time#bell#" and indexes = [0, 2, 5]. Here for each index, we will recover the word by reading from the reference string from that index until we reach the "#" symbol.So we have to find what is the length of the shortest reference string S possible that encodes the given words? So for the ... Read More
445 Views
Suppose we have given a head; this is the head node of a linked list containing unique integer values. Now we are also given the list G, a subset of the values in the linked list. We have to find the number of connected components in G, where two values are connected if they appear consecutively in the linked list. So if the list is like [0, 1, 2, 3] and G = [0, 1, 3], then output will be 2, as 0 and 1 are connected, so there are two lists [0, 1] and [3].To solve this, we will ... Read More
176 Views
Suppose we partition a row of numbers A into at most K adjacent groups, then we will set score as the sum of the average of each group. We have to find that what is the largest score that we can achieve. Suppose A = [9, 1, 2, 3, 9] and K is 3, then the result will be 20, this is because, the best choice is to partition A into [9], [1, 2, 3], [9]. So the answer is 9 + (1 + 2 + 3) / 3 + 9 = 20. We could have also partitioned A into ... Read More
355 Views
Suppose we are playing a simplified Pacman game. Now we start at the point (0, 0), and our destination is (target[0], target[1]). There are several ghosts on the map, Here the i-th ghost starts at (ghosts[i][0], ghosts[i][1]). In each turn, we and all ghosts simultaneously (may) move in one of 4 cardinal directions − north, east, west, or south, going from the last point to a new point 1 unit of distance away. We can escape if and only if we can reach the target before any ghost reaches us (for any given moves the ghosts may take.) If we ... Read More
506 Views
Suppose In a forest, each rabbit has some color. Now some subset of rabbits (possibly all of them) will tell us how many other rabbits have the same color as them. Those answers are placed in an array. We have to find the minimum number of rabbits that could be in the forest. So if the input is like [1, 1, 2], then the output will be 5, as the two rabbits that answered "1" that could both be the same color, say white. Now the rabbit than answered "2" can't be white or the answers would be inconsistent. Say ... Read More
1K+ Views
Suppose on the first row, we have a 0. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 by 01, and each occurrence of 1 by 10. Suppose we have N rows and index K, we have to find the K-th indexed symbol in row N. (The values of K are 1-indexed.) (1 indexed). So if N = 4 and K = 5, then the output will be 1. This is because −Row 1: 0Row 2: 01Row 3: 0110Row 4: 01101001To solve this, we will follow these steps −Suppose the name of ... Read More
412 Views
Suppose we have some permutation A of [0, 1, ..., N - 1], where N is the length of A. Now the number of (global) inversions is the number of i < j with 0 A[j]. And the number of local inversions is the number of i with 0 A[i+1]. We have to return true if and only if the number of global inversions is equal to the number of local inversions. So if the input is like [1, 0, 2], then return true, as there is only one local inversion and one global inversion.To solve this, we ... Read More
249 Views
Suppose you are standing at position 0 on an infinite number line. Now there is a goal at position target. Here in each move, you can either go to the left side or the right side. During the n-th move (starting from 1), you take n steps. We have to find the minimum number of steps required to reach the destination. So if the input is like target = 3, then we need 2 steps. From 0 to 1, from 1 to 3.To solve this, we will follow these steps −target := |target|, cnt := 0while target > 0, decrease ... Read More
584 Views
Suppose we have a non-negative integer N, we have to find the largest number that is less than or equal to N with monotone increasing digits. We know that an integer has monotone increasing digits if and only if each pair of adjacent digits’ x and y satisfy x = s[i – 1]increase i by 1if i < nwhile i > 0 and s[i – 1] > s[i], thendecrease i by 1decrease s[i] by 1for j in range i + 1 to ns[j] := ‘9’return s as numberLet us see the following implementation to get better understanding −Example Live Demo#include ... Read More
443 Views
Suppose we have one NxN chessboard, a knight starts at the r-th row and c-th column and attempts to make exactly K moves. Here the rows and columns are 0 indexed, so the top-left square is (0, 0), and the bottom-right square is (N-1, N-1).A knight can move in 8 different cells from a cell, that can be shown in this diagram −Each time the knight is to move, it chooses one of eight possible moves randomly. The knight continues moving until it has made exactly K moves or has moved off the chessboard. We have to find the probability ... Read More