
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

886 Views
A Consecutive sequence is a series of numbers where each number follows the previous one without any missing the order like 1, 2, 3, 4. It is a set of numbers where each number appears in increasing order by 1, even if not adjacent. We can find the Consecutive sequences in data structures of Python such as lists, strings, tuple, etc. Using set() function set() is the built-in function in Python which is used to create a Set data structure. This function is used to eliminate the duplicates from the given input. We can use set() function to find the ... Read More

354 Views
In Python, a string is immutable data structure in which sequence of characters are enclosed in double("") or single quotes(''). In some cases, we need to find the length of the longest subsequence of characters that can be rearranged to form a palindrome. This type of subsequence is referred to as a palindromic anagram subsequence. To solve this, we need to count how many characters appear an even number of times and at most one character can appear an odd number of times. An anagram is a word or phrase formed by rearranging the letters of another word or phrase ... Read More

404 Views
In Python, a list is a ordered and mutable data structure where elements are enclosed in square braces []. In some scenarios, we may need to count how many elements to the right of each element in the list are smaller than it. Using Binary Search with bisect_left() Function The bisect_left() Function of the bisect method is used locate the insertion point for an element in a sorted list to maintain the list's sorted order. The insertion point returned by bisect_left() is the index where the element can be inserted without violating the sort order by placing it before any ... Read More

449 Views
In Python, datastructures such as string, list etc., may contain duplicates of a value. In few scenarios, we may need to find which element appears only once while all others elements appear multiple times. Let's go through different methods to find which element occurs exactly once in Python. Using Bitwise XOR The XOR is abbrivated as Exclusive OR is a bitwise operator which returns 1 if the corresponding bits of two operands are different otherwise, it returns 0 if they are same. In Python, we can use the ^ between two operands to perform Exclusive OR operation. Example Following is ... Read More

594 Views
Suppose we have a a list of color strings, these may contain "red", "green" and "blue", we have to partition the list so that the red come before green, and green come before blue.So, if the input is like colors = ["blue", "green", "blue", "red", "red"], then the output will be ['red', 'red', 'green', 'blue', 'blue']To solve this, we will follow these steps −green := 0, blue := 0, red := 0for each string in strs, doif string is same as "red", thenstrs[blue] := "blue"blue := blue + 1strs[green] := "green"green := green + 1strs[red] := "red"red := red + ... Read More

1K+ Views
Suppose we have a sorted linked list node of size n, we have to create a binary search tree by Taking the value of the k = floor of (n / 2) the smallest setting it as the root. Then recursively constructing the left subtree using the linked list left of the kth node. And recursively constructing the right subtree using the linked list right of the kth node.So, if the input is like [2, 4, 5, 7, 10, 15], then the output will beTo solve this, we will follow these steps−Define a method solve(), this will take nodeif node ... Read More

411 Views
Suppose we have a binary search tree, we have to convert it to a singly linked list using levelorder traversal.So, if the input is likethen the output will be [5, 4, 10, 2, 7, 15, ]To solve this, we will follow these steps −head := a new linked list nodecurrNode := headq := a list with value rootwhile q is not empty, docurr := delete first element from qif curr is not null, thennext of currNode := a new linked list node with value of currcurrNode := next of currNodeinsert left of curr at the end of qinsert right curr ... Read More

140 Views
Suppose we have binary tree, we have to show the values of each level by alternating from going left-to-right and right-to-left.So, if the input is likethen the output will be [5, -10, 4, -2, -7, 15]To solve this, we will follow these steps −if root is null, thenreturn a new lists1 := a list initially insert roots2 := a new listres := a new listwhile s1 is not empty or s2 is not empty, dowhile s1 is not empty, donode := delete last element from s1if left of node is not null, theninsert left of node at the end of ... Read More

369 Views
Suppose we have a string s containing brackets parenthesis "(" and ")", we have to find the length of the longest subsequence of balanced brackets.So, if the input is like s = "())(()(", then the output will be 4, as we can take the subsequence like "()()"To solve this, we will follow these steps −res := 0n := size of sclose := 0for i in range n - 1 to 0, decrease by 1, doif s[i] is same as ")", thenclose := close + 1otherwise, if close > 0, thenclose := close - 1res := res + 2return resLet us ... Read More

375 Views
Suppose we have a binary tree; we have to find the value of the deepest node. If there are more than one deepest node, then return the leftmost deepest node.So, if the input is likethen the output will be 4 as 4 and 7 are deepest but 4 is left most.To solve this, we will follow these steps −queue := a queue with one node root.left_max := value of rootwhile size of queue > 0, dolevel_size := size of queuefor i in range 0 to level_size, dotemp := first element from queue and delete itif i is same as 0, ... Read More