
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 10476 Articles for Python

269 Views
Suppose we have one 2D array of characters called grid of size m x n. We have to check whether we can detect a cycle inside it or not. Here a cycle is a path of length 4 or more in the grid that starts and ends at the same position. We can move in four directions (up, down, left, or right), if it has the same value of the current cell, and we cannot revisit some cell.So, if the input is likemmmpmkmmmmsmftmmthen the output will be True, because the green cells are forming cycle.To solve this, we will follow ... Read More

293 Views
Suppose we have a number n. So consider there are n oranges in the kitchen and we eat some of these oranges every day maintaining these rules: 1. Eat single orange. 2. If n is even, then eat n/2 oranges. 3. If n is divisible by 3 can eat 2*(n/3) oranges. We can select only one option each day. We have to find the minimum number of days to eat n oranges.So, if the input is like n = 10, then the output will be 4 becauseOn day 1 eat 1 orange, 10 - 1 = 9.On day 2 eat ... Read More

789 Views
Suppose we have a value n and an array called cuts. Consider there is a wooden stick of length n units. The stick is labelled from 0 to n. Here cuts[i] represents a position where we can cut. We should perform the cuts in order, but we can change the order of the cuts as we want. Here the cost of one cut is the size of the stick to be cut, and the total cost is the sum of costs of all cuts. We have to find the minimum total cost of the cuts.So, if the input is like ... Read More

535 Views
Suppose we have a numeric string s. As we know an awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome. We have to find the length of the maximum length awesome substring of s.So, if the input is like s = "4353526", then the output will be 5 because "35352" is the longest awesome substring. we can make "35253" palindrome.To solve this, we will follow these steps −n := 0pos_map := a map containing a key 0 and corresponding value is size of smax_len := 1for ... Read More

586 Views
Suppose we have two arrays nums1 and nums2. A valid path is defined as follows −Select nums1 or nums2 to traverse (from index-0).Traverse the array from left to right.Now, if we are moving through any value that is present in nums1 and nums2 we can change the path to the other array. Here the score is the sum of unique values in a valid path. We have to find the maximum score we can get of all possible valid paths. If the answer is too large then return result modulo 10^9+7.So, if the input is like nums1 = [3, 5, ... Read More

231 Views
Suppose we have a string s and another value k. We can delete at most k characters from s such that the length of run-length encoded version of s is minimum. As we know the run-length encoding is a string compression method that replaces consecutive identical characters (2 or more times) with the concatenation of the character and the number marking the count of the characters. For example, if we have a string "xxyzzz" then we replace "xx" by "x2" and replace "zzz" by "z3". So compressed string is now "x2yz3". So in this problem we have to find the ... Read More

332 Views
Suppose we have two arrays nums and multipliers of size n and m respectively (n >= m). The arrays are 1-indexed. Now our initial score is 0. We want to perform exactly m operations. On the ith operation (1-indexed), we will −Select one value from x from either the start or the end of the nums.Add multipliers[i] * x to the score.Remove x from the array nums.We have to find the maximum score after performing m operations.So, if the input is like nums = [5, 10, 15], multipliers = [5, 3, 2], then the output will be 115 because we ... Read More

324 Views
Suppose we have an array called target with positive values. Now consider an array initial of same size with all zeros. We have to find the minimum number of operations required to generate a target array from the initial if we do this operation: (Select any subarray from initial and increment each value by one.)So, if the input is like target = [2, 3, 4, 3, 2], then the output will be 4 because initially array was [0, 0, 0, 0, 0] first pass select subarray from index 0 to 4 and increase it by 1, so array will be ... Read More

769 Views
Suppose we have a binary string called boxes, where boxes[i] is '0' indicates the ith box is empty, and '1' indicates it contains one ball. Now, in one operation, we can move one ball from a box to an adjacent box. After doing so, there may be more than one ball in some boxes. We have to find an array answer of size n, where answer[i] is the minimum number of operations needed to move all the balls to the ith box.So, if the input is like boxes = "1101", then the output will be [4, 3, 4, 5]To put ... Read More

644 Views
Suppose we have a string s with only lowercase letters, we have to find find the maximum number of non-empty substrings of s that meet the following rulesSubstrings are non-overlappingA substring that contains a specific character ch must also contain all occurrences of ch.We have to find the maximum number of substrings that meet these two conditions. If there are more than one such solutions with the same number of substrings, then return that with minimum total length.So, if the input is like s = "pqstpqqprrr", then the output will be ["s", "t", "rrr"] because all of the possible substrings ... Read More