
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

339 Views
Suppose we have a binary array data, we have to find the minimum number of swaps required to group all 1’s stored in the array together in any place in the array. So if the array is like [1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1], then the output will be 3, as possible solution is [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]To solve this, we will follow these steps −set one := 0, n:= length of data arraymake an array summ of size n, and fill this with 0, set summ[0] := ... Read More

598 Views
Suppose we have to Implement a SnapshotArray that supports the following interfaces −SnapshotArray(int length) this will initialize the array-like data structure with the given length. Initially, each element equals 0.set(index, val) this will sets the element at the given index to be equal to val.snap() will take a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.get(index, snap_id) this will return the value at the given index, at the time we took the snapshot with the given snap_idSo if the array size is 2, it is set using [0, 5], after ... Read More

522 Views
Suppose there are two players play a turn-based game on a binary tree. We have the root of this binary tree and the number of nodes n in the tree. Here n is odd, and each node has a distinct value from 1 to n. At first, the first player names a value x with 1

394 Views
Suppose we have an array nums of integers, a move operation is actually choosing any element and decreasing it by 1. An array A is a zigzag array if either 1 or 2 is satisfied −Every even-indexed element is greater than adjacent elements, So. A[0] > A[1] < A[2] > A[3] < A[4] > ... and so on.Every odd-indexed element is greater than adjacent elements, So. A[0] < A[1] > A[2] < A[3] > A[4] < ... and so on.We have to find the minimum number of moves to transform the given array nums into a zigzag array.So if the ... Read More

415 Views
Suppose there are N cities numbered from 1 to N. We have connections, where each connection [i] is [city1, city2, cost] this represents the cost to connect city1 and city2 together. We have to find the minimum cost so that for every pair of cities, there exists a path of connections (possibly of length 1) that connects those two cities together. The cost is the sum of the connection costs used. If the task is impossible, return -1.So if the graph is like −Then the output will be 6, Choosing any two cities will connect all cities, so we choose ... Read More

672 Views
Suppose we have directed graph, with nodes labelled 0, 1, ..., n-1. In this graph, each edge is colored with either red or blue colors, and there could be self-edges or parallel edges. Each [i, j] in red_edges indicates a red directed edge from node i to node j. Similarly, each [i, j] in blue_edges indicates a blue directed edge from node i to node j. We have to find an array answer of length n, where each answer[X] is the length of the shortest path from node 0 to node X such that the edge colors alternate along the ... Read More

170 Views
Suppose we have a rooted binary tree, we have to return the lowest common ancestor of its deepest leaves. We have to keep in mind that −The node of a binary tree is a leaf node if and only if it has no childrenThe depth of the root of the tree is 0, and when the depth of a node is d, the depth of each of its children is d+1.The lowest common ancestor of a set S of nodes in the node A with the largest depth such that every node in S is in the subtree with root ... Read More

178 Views
Suppose we have the root of a binary tree; we have to find the maximum average value of any subtree of that tree. So if the tree is like −The output will be 6, this is because, for node 5, it will be (5 + 6 + 1)/ 3 = 4, then for node 6 it will be 6 / 1 = 6, and for node 1, it will be 1 / 1 = 1, so the max is 6.To solve this, we will follow these steps −res := 0Define a method called solve(), this will take rootif root is ... Read More

220 Views
Suppose in an infinite binary tree where every node has two children, the nodes are labelled in row order. Now in the odd numbered rows (the first, third, fifth, ...), the labelling is left to right, and in the even numbered rows (second, fourth, sixth, ...), the labelling is right to left. So the tree will be like −So we have given the label of a node in this tree, we have to find the labels in the path from the root of the tree to the node with that label. So if the input is label = 14, then ... Read More

133 Views
Suppose in a social group, there are N different people, with unique integer ids from 0 to N-1. Here we have a list of logs, where each logs[i] = [time, id_A, id_B] contains a non-negative integer timestamp, and the ids of two different people. Each log is showing the time in which two different people became friends. If A is friends with B, then B is friends with A. Let's say that person A is acquainted with person B if A is friends with B, or A is a friend of someone acquainted with B. We have to find the ... Read More