
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 33676 Articles for Programming

396 Views
The 3Sum Smaller is one of the problem variations in which we need to find the number of triplets in an array such that their sum is less than a given target. We are given an array of n integers called nums and a target value, and we have to find the number of index triplets (i, j, k) where i, j, k are indices of an array all in range 0 to n – 1, such that they satisfy the condition: nums[i] + nums[j] + nums[k]

194 Views
In this article will explain a popular coding problem that involves verifying whether a given preorder sequence can represent a valid binary search tree (BST). We will discuss the problem statement, provide examples, algorithm to solve, and a C++ implementation of the solution. Problem Statement Algorithm to Solve Problem C++ Program Time and Space Complexity Verify Preorder Sequence in Binary Search Tree Given an array containing the preorder traversal of a binary tree, we need to verify whether it ... Read More

288 Views
Suppose we have a number. The numbers can be regarded as a product of its factors. So, 8 = 2 x 2 x 2; = 2 x 4. We have to make one function that takes an integer n and return all possible combinations of its factors.So, if the input is like 12, then the output will be [[2, 6], [2, 2, 3], [3, 4]]To solve this, we will follow these steps −Define a function solve(), this will take n, target, start, define one list of lists called retif n is same as 1, then −return retif n is not ... Read More

1K+ Views
Suppose there is an array of meeting time intervals. There are two times start and end times [[s1,e1],[s2,e2],...] and each pair satisfies the rule (si < ei), We have to find the minimum number of conference rooms required.So, if the input is like [[0, 30], [5, 10], [15, 20]], then the output will be 2.To solve this, we will follow these steps −define one priority queue pqsort the intervals arrayret := 0for initialize i := 0, when i < size of intervals, update (increase i by 1), do −while (not pq is empty and top element of pq

725 Views
Suppose we have a 2D vector, we have to design and implement an iterator to flatten that 2d vector. There will be different methods as follows −next() − This will return the next element of the current elementhasNext() − This will check whether next element is present or notSo, if the input is like [[1, 2], [3], [4]] then if we call the functions as follows −iterator.next();iterator.next();iterator.next();iterator.hasNext();iterator.hasNext();iterator.next();iterator.hasNext();then the output will be [1, 2, 3, true, true, 4, false]To solve this, we will follow these steps −Define one 2D array vDefine initializer this will take one 2D array v, rowPointer := ... Read More

275 Views
Suppose we have a binary tree; we have to count the number of uni-value subtrees. Here the Uni-value subtree indicates all nodes of the subtree have the same value.So, if the input is like root = [5, 1, 5, 5, 5, null, 5], then the output will be 4To solve this, we will follow these steps −Define a function solve(), this will take node, if node is empty, then −return trueleft := solve(left of node)right := solve(right of node)if left is false or right is false, then −return falseif left of node is present and val of node is not ... Read More

198 Views
Suppose we have a string, we can "shift" each of its letter to its successive letter, so: "abc" can be changed to "bcd". We can keep doing this operation which forms the sequence: "abc" -> "bcd" -> ... -> "xyz". If we have a list of non-empty strings that contains only lowercase alphabets, we have to group all strings that belong to the same shifting sequence.So, if the input is like ["abc", "bcd", "acef", "xyz", "az", "ba", "a", "z"], then the output will be [ ["abc", "bcd", "xyz"], ["az", "ba"], ["acef"], ["a", "z"] ]To solve this, we will follow these ... Read More

477 Views
Suppose we have a length n. We have to find all strobogrammatic numbers that are of length n.As we know that a strobogrammatic number is a number that looks the same when rotated 180 degrees.So, if the input is like n = 2, then the output will be ["11", "69", "88", "96"]To solve this, we will follow these steps −Define an array retif n is odd, then −insert "0" at the end of retinsert "1" at the end of retinsert "8" at the end of retOtherwiseinsert blank string at the end of retfor n > 1, update n := n ... Read More

225 Views
Suppose we have a list of words and another two words called word1 and word2, we have to find the shortest distance between these two words in the list. Here word1 and word2 may be the same and they represent two individual words in the list. Let us assume that words = ["practice", "makes", "perfect", "skill", "makes"].So, if the input is like word1 = “makes”, word2 = “skill”, then the output will be 1To solve this, we will follow these steps −ret := 10^9, l1 := 10^9, l2 := -10^9n := size of wordsfor initialize i := 0, when i ... Read More

375 Views
Suppose there is a class that receives a list of words in the constructor, there will be a method that takes two words word1 and word2 and find the shortest distance between these two words in the list. That method will be called repeatedly many times with different parameters.Let us assume that words = ["practice", "makes", "perfect", "skill", "makes"].So, if the input is like word1 = “skill”, word2 = “practice”, then the output will be 3To solve this, we will follow these steps −Define one map mThe initializer takes an array of wordsfor initialize i := 0, when i < ... Read More