
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

286 Views
Suppose we have a list of lists called rooms. Each index i in rooms represents a room and rooms[i] represents different keys to open other rooms. The room 0 is open and we are at that room and every other room is locked. We can move freely between opened rooms; we have to check whether we can open every room or not.So, if the input is like rooms = [[2, 0], [3], [1], []], then the output will be True, as we start from room 0 and can go to room 2 with its key 2. From room 2 we ... Read More

387 Views
Suppose we have a list of numbers called nums. And it is representing the height of square blocks, we have to check whether the shape is symmetric over the y = x line or not.So, if the input is like nums = [7, 5, 3, 2, 2, 1, 1], then the output will be TrueTo solve this, we will follow these steps:i := 0j := size of nums - 1while i

176 Views
Suppose we have four list of numbers A, B, C and D and also have another number target. We have to find the number of different unique indices i, j, k, l such that A[i] + B[j] + C[k] + D[l] ≤ target.So, if the input is like A = [3, 2] B = [5, 3] C = [1] D = [2, 3] target = 9, then the output will be 3, as We can pick the following combinations: [3, 3, 1, 2] [3, 3, 1, 2] [2, 3, 1, 3]To solve this, we will follow these steps:temp_list := a ... Read More

2K+ Views
Suppose we have a 2D matrix mat. We have to print the matrix elements in a spiral way. At first starting from the first row (mat[0, 0]), print the whole content and then follow the last column to print, then the last row, and so on, thus it prints the elements in a spiral fashion.So, if the input is like71092916239142759911then the output will be [7, 10, 9, 1, 3, 4, 5, 11, 9, 9, 2, 9, 6, 2, 9, 2, 1, 7]To solve this, we will follow these steps:d := 0top := 0, down := row count of matrix – 1, left := 0, right := column count of matrix - 1c := 0res := a new listdirection := 0while top

5K+ Views
Suppose we have a linked list. We have to sort the list into ascending order.So, if the input is like [5, 8, 4, 1, 5, 6, 3], then the output will be [1, 3, 4, 5, 5, 6, 8, ]To solve this, we will follow these steps:values := a new listhead := nodewhile node is not null, doinsert value of node at the end of valuesnode := next of nodesort the list valuesvalues := make a double ended queue by taking elements of valuesnode := headwhile node is not null, dovalue of node := left element of queue and delete ... Read More

3K+ Views
Suppose we have a list of numbers called items and another value n. A salesman has items in a bag with random IDs. The salesman can delete as many as n items from the bag. We have to find the minimum number of different IDs in the bag after n removals.So, if the input is like items = [2, 2, 6, 6] n = 2, then the output will be 1 as we he can sell two items with ID 2 or ID 6, then only items with single target will be there.To solve this, we will follow these steps:c ... Read More

315 Views
Suppose we have a binary tree; we have to find the depth of the second deepest leaf. If there are multiple deepest leaves, the second deepest leaf node will be the next highest one. As we know the root has a depth of 0.So, if the input is likethen the output will be 1, as the second deepest node is 3.To solve this, we will follow these steps:if root is null, thenreturn nullnodes := a new listinsert root at the end of nodescount := 0, prev := 0, now := 0while nodes is not empty, donew := a new listflag ... Read More

112 Views
Suppose we have two binary trees; we have to check whether the sequence of leaves left-to-right in both trees are the same.So, if the input is likethen the output will be True as the sequence is [2, 6] for both trees.To solve this, we will follow these steps:c := a new listDefine a function inorder() . This will take root, and cif c is null, thenc := a new listif root is not null, theninorder(left of root, c)if left of root is null and right of root is null, theninsert value of root at the end of cinorder(right of root, ... Read More

375 Views
Suppose we have a string and a set of delimiters, we have to reverse the words in the string while the relative ordering of the delimiters should not be changed.So, if the input is like s = "Computer/Network:Internet|tutorialspoint" delims = ["/", ":", '|'], then the output will be tutorialspoint/Internet:Network|ComputerTo solve this, we will follow these steps:words := a new listans := blank stringtemp := a map whereSeparate the words except the delimiter characters and insert them into words arrayseparate words when the character is in delimiter then add them into ans, otherwise read word from words array reversely and add ... Read More

211 Views
Suppose we have linked list, we also have two values i and j, we have to reverse the linked list from i to jth nodes. And finally return the updated list.So, if the input is like [1, 2, 3, 4, 5, 6, 7, 8, 9] i = 2 j = 6, then the output will be [1, 2, 7, 6, 5, 4, 3, 8, 9, ]To solve this, we will follow these steps:prev_head := create a linked list node with value same as null and that points to nodeprev := prev_head, curr := nodeiterate through all values from 0 to ... Read More