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
Programming Articles - Page 1012 of 3363
277 Views
Suppose we have a list of elements called nums we also have another value k. Now let us consider an operation where we select an element from nums and negate it. We can perform exactly k number of operations. We have to find the maximum resulting sum that can be generated.So, if the input is like nums = [2, 1, -6, -2] k = 3, then the output will be 9, if we negate -6 and -2 and 1 shall get [2, -1, 6, 2] and its sum is 9.To solve this, we will follow these steps −n := size ... Read More
273 Views
Suppose we have two arrays called nums and values, both contains integers and the values of nums are strictly increasing and their lengths are also same. We have to find the value of v for a pair of indices i, j, such that: i ≤ j that maximizes v = values[i] + values[j] + nums[j] - nums[i].So, if the input is like nums = [1, 2, 7] values = [-4, 6, 5], then the output will be 16, if we take pick i = 1 and j = 2 we get 6 + 5 + 7 - 2 = 16.To ... Read More
697 Views
Suppose we have a binary matrix; we have to find the number of elements in matrix that follows the following rules −matrix[r, c] = 1matrix[r, j] = 0 for every j when j is not equal to c and matrix[i, c] = 0 for every i when i is not equal to r.So, if the input is like001100010then the output will be 3, because we have cells (0, 2), (1, 0) and (2, 1) those meet the criteria.To solve this, we will follow these steps −if matrix is empty, thenreturn 0row := a list of sum of all row entries ... Read More
349 Views
Suppose we have a list of numbers called nums, that contains only non-negative numbers. If there are exactly k number of elements in nums that are greater than or equal to k, find the value k. If we cannot find such, then return -1.So, if the input is like nums = [6, 4, 0, 8, 2, 9], then the output will be 4, because there are exactly 4 elements that are greater than or equal to 4: [6, 4, 8, 9].To solve this, we will follow these steps −sort the list nums in reverse orderfor i in range 1 to ... Read More
613 Views
Suppose we have an array A and another value k. We have to form an array arr whose size is k bu taking elements from A and minimize the unfairness. Here the unfairness is calculated by this formula −(𝑚𝑎𝑥𝑖𝑚𝑢𝑚 𝑜𝑓 𝑎𝑟𝑟) − (𝑚𝑖𝑛𝑖𝑚𝑢𝑚 𝑜𝑓 𝑎𝑟𝑟)So, if the input is like A = [25, 120, 350, 150, 2500, 25, 35] and k = 3, then the output will be 10, because we can take elements [25, 25, 35] so max(arr) = 35 and min(arr) = 25. So their difference is 10.To solve this, we will follow these steps −i:= 0sort the ... Read More
169 Views
Suppose we have a list of list of strings called shows, also have a list of integers called durations, and another value k, here shows[i] and durations[i] represent a show and its duration watched by the ith man, we have to find the total duration watched of the k most watched shows.So, if the input is like shows = ["The BGT", "Jack jumper", "The BGT", "Jokers Company", "Music magic"] durations = [10, 8, 10, 18, 9] k = 2, then the output will be 38, as the top 2 most watched shows are "Jokers Company" and "The BGT" and total ... Read More
334 Views
Suppose we have a list of intervals and a value called point. Each interval interval[i] contains [si, ei] represents start time and end time of interval i (both inclusive). We have to find the number of intervals that are intersecting at given point.So, if the input is like intervals = [[2, 6],[4, 10],[5, 9],[11, 14]] point = 5, then the output will be 3, because at time 5, there are 3 intervals those are [3, 6], [4, 10], [5, 9]To solve this, we will follow these steps −count := 0for each start time i and end time j in intervals, doif point >= i and point = i and point
298 Views
Suppose we have a number n. Consider x = rand() mod n, where rand() function generates integers between 0 and 10^100 (both inclusive) uniformly at random. And$$Y = \sqrt{x+\sqrt{x+\sqrt{x+\sqrt{x+...}}}}$$We have to find the expected value of Y. The value of n will be in range 1 and 5*10^6.So, if the input is like n = 5, then the output will be 1.696To solve this, we will follow these steps −err := 2235.023971557617max_n := 5 * 10^6pref := a list initially contains a single 0for i in range 1 to 5 * 10^6, doinsert (last item of pref + (1 +(4*i ... Read More
1K+ Views
Suppose we have a list of elements; these elements are stored in a singly linked list. We also have a value pos and value val. We have to insert val before index pos of the linked list.So, if the input is like nums = [1, 5, 3, 6, 8] pos = 3 val = 7, then the output will be [1, 5, 3, 7, 6, 8]To solve this, we will follow these steps −new := create a linked list node with value same as valif pos is same as 0, thennext of new := list_headreturn newtemp := list_headwhile temp is ... Read More
180 Views
Suppose we have two strings s1 and s2. We have to find the size of longest string s3 which is special substring of both s1 and s2.We can say a string x is special substring of another string y if x can be generated by removing 0 or more characters from y.So, if the input is like s1 = 'pineapple' s2 = 'people', then the output will be 5 as the special substring is 'peple', of size 5.To solve this, we will follow these steps −prev := a new dictionary, where if some key is not present, return 0for i ... Read More