
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 33676 Articles for Programming

122 Views
Suppose we have a list of numbers called nums that stored 0s and 1s. We have another value k.Now consider there is an operation where we flip a sublist of length k such that all 1s will be 0s and all 0s will be 1s. We have to find the minimum number of operations required to change nums into all 1s to 0s. If we cannot change it return -1.So, if the input is like nums = [1, 1, 1, 0, 0, 1, 1, 1], k = 3, then the output will be 2, as we can flip the first ... Read More

699 Views
Suppose we have a list of numbers called nums that are representing position of houses on a 1-dimensional line. Now consider we have 3 street lights that we can put anywhere on the line and a light at position x lights up all houses in range [x - r, x + r], inclusive. We have to find the smallest r required to light up all houses.So, if the input is like nums = [4, 5, 6, 7], then the output will be 0.5, as we can place the lamps on 4.5, 5.5 and 6.5 so r = 0.5. So these ... Read More

168 Views
Suppose we have two strings s and t of digits, we have to find a way to remove digits in the strings so that: 1. Two strings are same 2. The sum of the digits that are deleted is minimized Finally return the minimized sum.So, if the input is like s = "41272" t = "172", then the output will be 6, as we can remove "4" and "2" from the first string to get "172".To solve this, we will follow these steps −Define a function lcs() . This will take a, b, m, ntable := a 2d matrix of ... Read More

410 Views
Suppose we have two strings s and t, we have to find the size of a minimum substring in s that contains all the characters of t. If there is no such substring exists then return -1.So, if the input is like s = "thegrumpywizardmakes" t = "wake", then the output will be 10, as the shortest substring that contains "wake" is "wizardmake" (length of 10).To solve this, we will follow these steps −counter := frequency of each character in bstart := 0min_subs := infrem := count of distinct characters in bfor end in range 0 to size of a, ... Read More

401 Views
Suppose we have a string s, we have to find the minimum number of adjacent swaps needed to make it into a palindrome. If there is no such way to solve, then return -1.So, if the input is like s = "xxyy", then the output will be 2, as we can swap the middle "x" and "y" so string is "xyxy" and then swap the first two "x" and "y" to get "yxxy", and this is palindrome.To solve this, we will follow these steps −Define a function util() . This will take sseen := a new mapfor each i in ... Read More

255 Views
Suppose we have a list of numbers nums, we can say that two numbers nums[i] ≤ nums[j] are adjacent when there is no number in between (nums[i], nums[j]) in nums. We have to find the minimum possible |j - i| such that nums[j] and nums[i] are adjacent.So, if the input is like nums = [1, -9, 6, -6, 2], then the output will be 2, as we can see that 2 and 6 are adjacent and they are 2 indices away from each other.To solve this, we will follow these steps −indexes := a new mapfor each index i and ... Read More

272 Views
Suppose we have a 4 x 4 board of letters and a list of words, we have to find the largest number of words that can be generated in the board by a sequence of adjacent letters, using one cell at most once per word (but we can reuse cells for other words). We can go up, down, left, right, or diagonal direction.So, if the input is likembfdxayatztrsqqqwords = ["bat", "far", "mat"], then the output will be 3, as we can generate mat [0, 1] → [1, 1] → [2, 0], bat [0, 2] → [1, 1] → [2, 2], ... Read More

163 Views
Suppose we have a list of non-overlapping intervals. These are sorted based on end time. We have another interval target, find final interval after merging target so that intervals are still non-overlapping and sorted.So, if the input is like intervals = [[1, 15],[25, 35],[75, 90]], target = [10, 30], then the output will be [[1, 35], [75, 90]] as first two intervals [1, 15] and [25, 35] are merged.To solve this, we will follow these steps −insert target at the end of ivsort iv based on start timeres := a new list with first intervali := 1while i < size of iv, doif start time of iv[i]

189 Views
Suppose we have a list of numbers nums and a list of queries where each query contains [x, limit]. We have to find a list such that for each query [x, limit], we find an element e in nums such that e ≤ limit and e XOR x is maximized. If there is no such element, return -1.So, if the input is like nums = [3, 5, 9] queries = [[4, 6], [2, 0]], then the output will be [3, -1], as for the first query, we can use 2 or 4 in nums. 3 ^ 4 = 7 while ... Read More

210 Views
Suppose we have a string s and another string t. And t is a subsequence of s. We have to find the maximum length of a substring that we can remove from s so that, t is still a subsequence of s.So, if the input is like s = "xyzxyxz" t = "yz", then the output will be 4, as We can remove the substring "abca"To solve this, we will follow these steps −left := a new list, right := also a new listc1 := -1, c2 := -1, c3 := -1j := 0for i in range 0 to size ... Read More