
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

648 Views
Suppose we have a friend named Bob, and he is playing a game with himself. He gives himself a list of numbers called nums. Now in each turn, Bob selects two elements of the list and replaces them with one positive integer with the same sum as the numbers he selected. Bob declares the victory when all of the number in the array are even. We have to find the minimum number of turns are required to make by Bob, so he can declare victory, if there is no such solution, then return -1.So, if the input is like [2, ... Read More

402 Views
Suppose we have a matrix, we have to find the total number of integers whose value is the largest in its row and column.So, if the input is like132465157then the output will be 2 as 6 and 7 are valid.To solve this, we will follow these steps −mat := matrixr_maxes := make a list of max elements of each row of matc_maxes := make a list of max elements of each column of mata := a new listfor r in range 0 to number of rows - 1, dofor c in range 0 to number of columns - 1, dov ... Read More

1K+ Views
Suppose we have a string s that is representing a number in base 3 (valid numbers 0, 1, or 2), we have to find its equivalent decimal integer.So, if the input is like "10122", then the output will be 98.To solve this, we will follow these steps −ans := 0for each digit c in s, doans := 3 * ans + creturn ansLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, s): ans = 0 for c in map(int, s): ans = 3 * ans + c return ans ob = Solution() print(ob.solve("10122"))Input"10122"Output98

114 Views
Suppose we have a number greater than 0, we have to check whether the number is power of two or not.So, if the input is like 1024, then the output will be True.To solve this, we will follow these steps −while n > 1, don := n / 2return true when n is same as 1, otherwise 0Let us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, n): while n > 1: n /= 2 return n == 1 ob = Solution() print(ob.solve(1024))Input1024OutputTrue

965 Views
Suppose we have a string s, we have to check whether it has all unique characters or not.So, if the input is like "world", then the output will be TrueTo solve this, we will follow these steps −set_var := a new set from all characters of sreturn true when size of set_var is same as size of s, otherwise falseLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, s): set_var = set(s) return len(set_var) == len(s) ob = Solution() print(ob.solve('hello')) print(ob.solve('world'))Inputhello worldOutputFalse TrueRead More

2K+ Views
Suppose we have a lowercase alphabet string called text. We have to find a new string where every character in text is mapped to its reverse in the alphabet. As an example, a becomes z, b becomes y and so on.So, if the input is like "abcdefg", then the output will be "zyxwvut"To solve this, we will follow these steps −N := ASCII of ('z') + ASCII of ('a')return ans by joining each character from ASCII value (N - ASCII of s) for each character s in textLet us see the following implementation to get better understanding −Example Live Democlass Solution: ... Read More

277 Views
Suppose we have head of a singly linked list, we have to check whether the values of the nodes are sorted in a strictly ascending order or not.So, if the input is like [2, 61, 105, 157], then the output will be True.To solve this, we will follow these steps −Define a function solve() . This will take headif head.next is null, thenreturn Trueif head.val >= head.next.val, thenreturn Falsereturn solve(head.next)Let us see the following implementation to get better understanding −Example Live Democlass ListNode: def __init__(self, data, next = None): self.val = data self.next = ... Read More

705 Views
Suppose we have a list of numbers called nums, we have to check whether there are two numbers such that one is a triple of another or not.So, if the input is like nums = [2, 3, 10, 7, 9], then the output will be True, as 9 is the triple of 3To solve this, we will follow these steps −i := 0sort the list nj := 1while j < size of n, doif 3*n[i] is same as n[j], thenreturn Trueif 3*n[i] > n[j], thenj := j + 1otherwise, i := i + 1return FalseLet us see the following implementation ... Read More

204 Views
Suppose er have a string dictionary, the dictionary is representing a partial lexicographic ordering of ancient astronauts' dictionary. So, if we have a string s, we have to check whether it's a lexicographically sorted string according to this ancient astronaut dictionary or not.So, if the input is like dictionary = "bdc", s = "bbbb h ddd i cccc", then the output will be TrueTo solve this, we will follow these steps −l := size of astro_dictif l is same as 0, thenreturn Truei := 0for each character c in s, doif c in astro_dict, thenwhile i < l and astro_dict[i] ... Read More

4K+ Views
Suppose we have a string that is representing a 12-hour clock time with suffix am or pm, and an integer n is also given, we will add n minutes to the time and return the new time in the same format.So, if the input is like s = "8:20pm" and n = 150, then the output will be 10:50pmTo solve this, we will follow these steps −h, m := take the hour and minute part from sh := h mod 12if the time s is in 'pm', thenh := h + 12t := h * 60 + m + nh ... Read More