
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

5K+ Views
Suppose we have one 9x9 Sudoku board. We have to check whether that is valid or now. Only the filled cells need to be validated according to the following rules −Each row must contain the digits from 1-9 without repetition.Each column must contain the digits from 1-9 without repetition.Each of the 9 (3x3) sub-boxes of the grid must contain the digits from 1-9 without repetition.Suppose the Sudoku grid is like −537619598686348317266284195879This is valid.To solve this, we will follow these steps −for i in range 0 to 8create some empty dictionary called row, col and block, row_cube := 3 * (i ... Read More

1K+ Views
Suppose we have an array of integers A. This is sorted in ascending order, we have to find the starting and ending position of a given target value. When the target is not found in the array, return [-1, -1]. So if the array is like [2, 2, 2, 3, 4, 4, 4, 4, 5, 5, 6], and target is 4, then the output will be [4, 7]To solve this, we will follow these steps −Initially res := [-1, -1], set low := 0, high := length of array Awhile low < highmid := low + (high – low)/2if A[mid] ... Read More

1K+ Views
Consider we have an array sorted in ascending order, and that is rotated at some pivot unknown to you beforehand. For example, [0, 1, 2, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2]. We have given a target value to the search. If we can get it in the array, then return its index, otherwise return -1. We can assume no duplicate exists in the array. So if the array is like [4, 5, 6, 7, 0, 1, 2], then the output will be 4. as the index of this element is present at index ... Read More

3K+ Views
Suppose we have a value n. We have to generate all possible well-formed parentheses where n number of opening and closing parentheses are present. So if the value of n = 3, then the parentheses set will be ["()()()", "()(())", "(())()", "(()())", "((()))"]To solve this, we will follow these steps −Define method called genParenthesisRec(). This takes left, right, temp string and result array. initially result array is emptyThe function genParenthesisRec, will work like belowif left = 0 and right := 0, then insert temp into result, and returnif left > 0getParenthesisRec(left – 1, right, temp + “(”, result)if right > ... Read More

689 Views
Suppose we have a linked list. We have to remove the Nth node from the end of the list, then return its head. So if the list is like [1, 2, 3, 4, 5, 6] and n = 3, then the returned list will be [1, 2, 3, 5, 6].To solve this, we will follow these steps −If there is no node after head, then return Nonefront := head, back := head, counter := 0 and fount := falsewhile counter

3K+ Views
Suppose we have a string containing digits from 2-9 inclusive. We have to return all possible letter combinations that the number could represent. One mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.12a b c3d e f4g h i5j k l6m n o7p q r s8t u v9w x y z*0#For an example, if the given string is “23”, then the possible strings will be [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”]To solve this, we will follow these steps −Define an array called solve ... Read More

6K+ Views
Suppose we have an array of numbers. It stores n integers, there are there elements a, b, c in the array, such that a + b + c = 0. Find all unique triplets in the array which satisfies the situation. So if the array is like [-1, 0, 1, 2, -1, -4], then the result will be [[-1, 1, 0], [-1, -1, 2]]To solve this, we will follow these steps −Sort the array nums, and define an array resfor i in range 0 to length of nums – 3if i > 0 and nums[i] = nums[i - 1], then ... Read More

431 Views
Suppose we have a set of n non-negative integers a1, a2, ..., an, each value represents a point at coordinate (i, a[i]). n vertical lines are present in such a way that the two endpoints of line i is at (i, a[i]) and (i, a[0]). We have to find two lines, which together with x-axis forms one container, so our goal is to find two columns where water volume is max. So if the array is like [1, 8, 6, 2, 5, 4, 8, 3, 7], then it will beIn the shaded part, the height is 7 and there are ... Read More

512 Views
Except for control characters, (+ ? . * ^ $ ( ) [ ] { } | \), all characters match themselves. You can escape a control character by preceding it with a backslash.Following table lists the regular expression syntax that is available in Python −Sr.No.Pattern & Description1^Matches beginning of line.2$Matches end of line.3.Matches any single character except newline. Using m option allows it to match newline as well.4[...]Matches any single character in brackets.5[^...]Matches any single character not in brackets6re*Matches 0 or more occurrences of preceding expression.7re+Matches 1 or more occurrence of preceding expression.8re?Matches 0 or 1 occurrence of preceding ... Read More

2K+ Views
Regular expression literals may include an optional modifier to control various aspects of matching. The modifiers are specified as an optional flag. You can provide multiple modifiers using exclusive OR (|), as shown previously and may be represented by one of these −Sr.No.Modifier & Description1re.IPerforms case-insensitive matching.2re.LInterprets words according to the current locale. This interpretation affects the alphabetic group (\w and \W), as well as word boundary behavior(\b and \B).3re.MMakes $ match the end of a line (not just the end of the string) and makes ^ match the start of any line (not just the start of the string).4re.SMakes ... Read More