
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

256 Views
Suppose we have a binary matrix where 0 is representing empty cell and 1 is representing a chess queen at that cell. We have to check whether we can fill this board and get a valid nqueen solution or not. As we know the n queens puzzle asks to place n queens on an n × n chessboard so that no two chess queens can attack each other.So, if the input is like1000000000000010000000010then the output will be True, as one solution is like −1000000100000010100000010To solve this, we will follow these steps −Define a function isSafe() . This will take board, ... Read More

130 Views
Suppose we have a string s. This s consists of opening and closing parenthesis only. We have to find the length of the longest valid (well-formed) parentheses substring. So if the input is like “))(())())”, then the result will be 6, as the valid string is “(())()”.To solve this, we will follow these steps −Make a stack, and insert -1., set ans := 0for i in range 0 to length of stack – 1if s[i] is opening parentheses, then insert i into stackotherwiseif stack is not empty and top of stack is not -1 and s[stack top] is opening parentheses, ... Read More

358 Views
Suppose we have two lists of numbers. One is called weights and another is called values. These are of same length, We also have two values called capacity and count. Here weights[i] and values[i] represent the weight and value of the ith item. We can hold at most capacity weight and at most count items in total, and we can take only one copy of each item, so we have to find the maximum amount of value we can get.So, if the input is like weights = [2, 2, 4, 6] values = [15, 15, 20, 35] capacity = 8 ... Read More

210 Views
Suppose we have a string s that is representing the initial conditions of some animals. Each animal can take one of three values: L, indicates the animal moved to left. R, indicates the animal moved to right. @, indicates the animal is standing still. Animals moving on a direction will pick up other animals unless the animal receives a force from the opposite direction. Then, it will stand still. We have to find the orientation of each animal when the animal stop moving.So, if the input is like s = "@@L@R@@@@L", then the output will be "LLL@RRRLLL"To solve this, we ... Read More

421 Views
Suppose we have a binary string s. Now suppose we can take some prefix of s and move it to the back. then, find the minimum number of characters that need to be flipped such that there will be no consecutive characters of the same value.So, if the input is like s = "10010101111", then the output will be 2, as we can take prefix "10", then move it to back so string is "01010111110" then flip 3rd and 5th bit from right to 0 ("01010101010").To solve this, we will follow these steps −ans := size of SN := size ... Read More

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

695 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