
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

4K+ Views
Suppose we have a positive number n, we will add all of its digits to get a new number. Now repeat this operation until it is less than 10.So, if the input is like 9625, then the output will be 4.To solve this, we will follow these steps −Define a method solve(), this will take nif n < 10, thenreturn ns := 0l := the floor of (log(n) base 10 + 1)while l > 0, dos := s + (n mod 10)n := quotient of n / 10l := l - 1return solve(s)Let us see the following implementation to get ... Read More

173 Views
Suppose we have two strings s and t, we have to check whether we can get t by removing 1 letter from s.So, if the input is like s = "world", t = "wrld", then the output will be True.To solve this, we will follow these steps −i:= 0n:= size of swhile i < n, dotemp:= substring of s[from index 0 to i-1] concatenate substring of s[from index i+1 to end]if temp is same as t, thenreturn Truei := i + 1return FalseLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, s, t): ... Read More

350 Views
Suppose we have a list of numbers A, we have to find all duplicate numbers and remove their last occurrences.So, if the input is like [10, 30, 40, 10, 30, 50], then the output will be [10, 30, 40, 50]To solve this, we will follow these steps −seen:= a new mapd:= a new mapfor i in range 0 to size of nums, doif nums[i] is not in d, thend[nums[i]]:= 1otherwise, d[nums[i]] := d[nums[i]] + 1i:= 0while i < size of nums, don:= d[nums[i]]if nums[i] is not in seen, thenseen[nums[i]]:= 1otherwise, seen[nums[i]] := seen[nums[i]] + 1if n is same as seen[nums[i]] ... Read More

243 Views
Suppose we have a list of numbers called A and another number k, we have to make a new set of possible elements {A[k], A[A[k]], A[A[A[k]]], ... } stopping before it's out of index. We have to find the size of this set, otherwise -1 when there is a cycle.So, if the input is like A = [1, 2, 3, 4, 5, 6, 7], k = 1, then the output will be 6 as A[1] = 2, A[2] = 3, A[3] = 4, A[4] = 5, A[5] = 6, A[6] = 7, So the set is {2, 3, 4, 5, ... Read More

368 Views
Suppose we have a string s, we have to find the index of the first recurring character in it. If we cannot find no recurring characters, then return -1.So, if the input is like "abcade", then the output will be 3, as 'a' is again present at index 3.To solve this, we will follow these steps −define a map charsfor i in range 0 to size of s, doif s[i] in chars, thenreturn iotherwise, chars[s[i]] := chars[s[i]] + 1return -1Let us see the following implementation to get better understanding −Example Live Demofrom collections import defaultdict class Solution: def solve(self, s): ... Read More

4K+ Views
Suppose we have a rectangle that is represented as a list with four elements [x1, y1, x2, y2], where (x1, y1) is the coordinates of its bottom-left corner, and (x2, y2) is the coordinates of its top-right corner. Two rectangles overlap when the area of their intersection is positive. So, two rectangles that only touch at the corner or edges do not overlap.So, if the input is like R1 = [0,0,2,2], R2 = [1,1,3,3], then the output will be True.To solve this, we will follow these steps −if R1[0]>=R2[2] or R1[2]=R2[2]) or (R1[2]

1K+ Views
Suppose we have a list of numbers called nums, we have to check whether there exist three numbers a, b, and c such that a^2 + b^2 = c^2.So, if the input is like [10, 2, 8, 5, 6], then the output will be True, as 8^2 + 6^2 = 64+36 = 100 = 10^2.To solve this, we will follow these steps −tmp := list of square of all numbers in nums in descending orderfor each index i and corresponding number n in tmp, dobase := nleft := i+1, right := size of tmp -1while left base, thenleft := ... Read More

757 Views
Suppose we have a number n greater than 1, we have to find all of its prime factors and return them in sorted sequence. We can write out a number as a product of prime numbers, they are its prime factors. And the same prime factor may occur more than once.So, if the input is like 42, then the output will be [2, 3, 7].To solve this, we will follow these steps −res:= a new listwhile n mod 2 is same as 0, doinsert 2 at the end of resn := quotient of n/2for i in range 3 to (square ... Read More

273 Views
Suppose we have two lists of numbers called nums and costs. Now consider, there is an operation where we can increase or decrease nums[i] for cost costs[i]. We can perform any number of these operations, and we want to make all elements equal in the nums. We have to find the minimum total cost required.So, if the input is like nums = [3, 2, 4] costs = [1, 10, 2], then the output will be 5, as if we can decrease the number 3 into 2 for a cost of 1. Then we can decrement 4 two times for a ... Read More

279 Views
Suppose we have a binary tree, we have to find the same tree but every node's value is replaced by its its value + all of the sums of its left and right subtrees.So, if the input is likethen the output will beTo solve this, we will follow these steps −Define a function tree_sum() . This will take root of a treeif root is null, thenreturn 0data of root := tree_sum(left of root) + tree_sum(right of root) + data of rootreturn data of rootFrom the main method, do the following:tree_sum(root)return rootLet us see the following implementation to get better understanding ... Read More