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
Server Side Programming Articles - Page 1746 of 2646
3K+ Views
Suppose we want to implement one stack using a queue. We have to define these methods for the stack.push(x) − Push x onto stack.pop() − Delete and return top element from stacktop() − Return the top element from stack.empty() − Return whether the stack is empty or not.So, if we call the functions push(10), push(20), then call pop(), pop(), then the output will be 20, 10To solve this, we will follow these steps −Define one deque qDefine a function push(), this will take x, insert x at the beginning of qDefine a function pop()k := first element of qdelete front ... Read More
265 Views
Suppose we have an array and an integer k, we have to check whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.So, if the input is like [1, 2, 4, 1] and k = 3, then the output will be TrueTo solve this, we will follow these steps −Define an array nn of pairsfor initialize i := 0, when i − size of nums, update (increase i by 1), do −insert {nums[i], i} at the end of nnsort the array ... Read More
4K+ Views
Suppose we have two strings s and t; we have to check whether they are isomorphic or not. Two strings are said to be isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.So, if the input is like s = "egg", t = "add”, then the output will be true, as e can map to a, and g can map to d.To solve this, we ... Read More
878 Views
Suppose we have a positive integer; we have to find its corresponding column title as appear in an Excel sheet. So [1 : A], [2 : B], [26 : Z], [27 : AA], [28 : AB] etc.So, if the input is like 28, then the output will be AB.To solve this, we will follow these steps −while n is non-zero, do −n := n - 1res := res + n mod 26 + ASCII of 'A'n := n / 26reverse the array resreturn resExample Let us see the following implementation to get a better understanding − Live Demo#include using namespace std; ... Read More
368 Views
Suppose we have a non-negative index k where k ≤ 33, we have to find the kth index row of Pascal's triangle.So, if the input is like 3, then the output will be [1,3,3,1]To solve this, we will follow these steps −Define an array pascal of size rowIndex + 1 and fill this with 0for initialize r := 0, when r
179 Views
Suppose we have a binary tree; we have to find the minimum depth of that tree. As we know the minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.So, if the input is likethen the output will be 2To solve this, we will follow these steps −Define an array aa of tree nodesinsert root at the end of aaDefine another array ak of tree nodeslevel := 0if root is null, then −return 0while size of aa is not equal to 0, do −clear the array ak(increase level by ... Read More
423 Views
Suppose we have two binary trees; we have to define a function to check whether they are the same or not. We know that the binary trees are considered the same when they are structurally identical and the nodes have the same value.So, if the input is like [1, 2, 3], [1, 2, 3], then the output will be TrueTo solve this, we will follow these steps −Define a function called isSameTree, this will take two tree nodes p and qif p is the same as NULL and q is same as NULL, then −return trueif p is the same ... Read More
1K+ Views
Suppose we have a sorted linked list; we have to delete all duplicates such that each element appears only once.So, if the input is like [1, 1, 2, 3, 3, 3, 4, 5, 5], then the output will be [1, 2, 3, 4, 5]To solve this, we will follow these steps −dummy := make a new node with value -infnext of dummy := headcurr = dummywhile curr is non-zero, do −next = next of currwhile (next is not null and val of next is same as val of curr), do −next := next of nextnext of curr := nextcurr := ... Read More
1K+ Views
Suppose we have a string s. s can hold any English letters and white-spaces. We have to find the length of last word in the string. If there is no last word, then return 0.So, if the input is like "I love Programming", then the output will be 11To solve this, we will follow these steps −n := 0for each word temp in a string −n := size of tempreturn nExampleLet us see the following implementation to get a better understanding − Live Demo#include using namespace std; class Solution { public: int lengthOfLastWord(string s){ stringstream str(s); ... Read More
593 Views
Suppose we have a sorted array arr and a target value, we have to find the index when the target is found. If that is not present, then return the index where it would be if it were inserted in order.So, if the input is like [1, 3, 4, 6, 6], and target = 5, then the output will be 3, as we can insert 5 at index 3, so the array will be [1, 3, 4, 5, 6, 6]To solve this, we will follow these steps−n := size of Aif n < 1, then −return 0low := 0, high ... Read More