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 898 of 2650
242 Views
Suppose we have an array nums and another value k, we have to find the most competitive subsequence of nums of size k. Here a subsequence s1 is more competitive than a subsequence s2 (of equal size) if in the first position where s1 and s2 differ, subsequence s1 has a number less than the corresponding number in s2.So, if the input is like nums = [4, 6, 3, 7] k = 2, then the output will be [3, 7] because among all subsequences of size 2, {[4, 6], [4, 3], [4, 7], [6, 3], [6, 7], [3, 7]}, the ... Read More
284 Views
Suppose we are given several buckets and x number of balls. If the balls are put into the bucket, a special force acts within them and we have to find out a way to maximize the minimum force between two balls. The force between two balls in a bucket of position p and q is |p - q|. The input given to us is the array containing the bucket positions and the number of balls x. We have to find out the minimum force between them.So, if the input is like pos = [2, 4, 6, 8, 10, 12], x ... Read More
160 Views
Suppose we have an array of called nums whose length is even, we have to check whether it is possible to reorder it in such a way that nums[2*i + 1] = 2*nums[2*i] for every 0 cnt[2 * x], thenreturn Falsecnt[2 * x] := cnt[2 * x] - cnt[x]return TrueExampleLet us see the following implementation to get better understanding −from collections import Counter def solve(nums): cnt = Counter(nums) for x in sorted(cnt, key=abs): if cnt[x] > cnt[2 * x]: return False cnt[2 * x] -= cnt[x] return True nums = [4,-2,2,-4] print(solve(nums))Input[6,0,8,2,1,5]OutputTrue
975 Views
Suppose we have two linked lists L1 and L2 of length m and n respectively, we also have two positions a and b. We have to remove nodes from L1 from a-th node to node b-th node and merge L2 in between.So, if the input is like L1 = [1, 5, 6, 7, 1, 6, 3, 9, 12] L2 = [5, 7, 1, 6] a = 3 b = 6, then the output will be [1, 5, 6, 5, 7, 1, 6, 9, 12]To solve this, we will follow these steps −head2 := L2, temp := L2while temp has next ... Read More
462 Views
Suppose in a conference, there are two types of people. The first type of people prefers a vegetarian lunch, and the other type prefers a non-vegetarian lunch. But there are a limited number of packets, and if the vegetarians receive a non-vegetarian packet or vice versa; they will not take that packet and wait until they get their preferred one. So, the two different types of packets and people are denoted as 0 for vegetarian and 1 for non-vegetarian. Now we are given two arrays, one containing n number of food packets denoted by 0 and 1 and another array ... Read More
354 Views
Suppose we have an array called nums. We can select exactly one index and remove the element from that index. (The index of the elements may change after the removal). We can say an array is fair when the sum of the odd-indexed values equals the sum of the even-indexed values. We have to find the number of indices that we could select such that after the removal, nums is fair.So, if the input is like nums = [5, 3, 7, 2], then the output will beRemove from index 0, array is [3, 7, 2], even position sum: 3+2 = ... Read More
503 Views
Suppose we have two values n and k. We have to find the lexicographically smallest string whose length is n and numeric value equal to k. The numeric value of a lowercase character is its position (starting from 1) in the alphabet, so the numeric value of character 'a' is 1, the numeric value of character 'b' is 2 and so on. And the numeric value of a string consisting of lowercase characters is the sum of its characters' numeric values.So, if the input is like n = 4 k = 16, then the output will be "aaam" because here ... Read More
376 Views
Suppose we have an array called nums and another value x. In one operation, we can either delete the leftmost or the rightmost element from the array and subtract the value from x. We have to find the minimum number of operations required to reduce x to exactly 0. If it is not possible then return -1.So, if the input is like nums = [4, 2, 9, 1, 4, 2, 3] x = 9, then the output will be 3 because at first we have to delete left most element 4, so array will be [2, 9, 1, 4, 2, ... Read More
283 Views
Suppose we have a string s, s is said to be good if there are no two different characters in s that have the same frequency. We have to find the minimum number of characters we need to delete to make s a good string.So, if the input is like s = "ssstttuu", then the output will be 2 because if we delete one 't', then there will be three 's', two 't' and two 'u', then again delete one, either 't' or 'u', to make them good.To solve this, we will follow these steps −val := a new map ... Read More
714 Views
Suppose we have a number n, we have to find the number of strings of size n that consist only of vowels (a, e, i, o, u) and they are lexicographically sorted. We can say that a string s is lexicographically sorted when for all valid index i, s[i] is the same as or comes before s[i+1] in the alphabet.So, if the input is like n = 2, then the output will be 15 because there are many strings like ["aa", "ae", "ai", "ao", "au", "ee", "ei", "eo", "eu", "ii", "io", "iu", "oo", "ou", "uu"].To solve this, we will follow ... Read More