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
Programming Articles - Page 1975 of 3363
319 Views
Suppose we have a positive integer n, we have to break it into the sum of at least two positive numbers and maximize the product of those integers. We have to find the maximum product we can get. So if the number is 10, then the answer will be 36, as 10 = 3 + 3 + 4, 3 * 3 * 4 = 36To solve this, we will follow these steps −Define a method solve(), this will take n, array dp and flagif n is 0, then return 1if dp[n] is not -1, then return dp[n]end := n – ... Read More
278 Views
Suppose we have a list of airline tickets represented by pairs of departure and arrival airports like [from, to], we have to reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. So, the itinerary must begin with JFK.So if the input is like [["MUC", "LHR"], ["JFK", "MUC"], ["SFO", "SJC"], ["LHR", "SFO"]], then the output will be ["JFK", "MUC", "LHR", "SFO", "SJC"].To solve this, we will follow these steps −Define array ret and a map called graph.Define a method called visit. This will take airport name as inputwhile size of the graph[airport] is ... Read More
511 Views
Suppose we have a string array called words, find the maximum value of length(word[i]) * length(word[j]) where the two words will not share the common letters. We can assume that each word will contain only lower case letters. If no such two words exist, then return 0. So if the input is like [“abcw”, “baz”, “foo”, “bar”, “xtfn”, “abcdef”], then the output will be 16, as two words can be “abcw”, “xtfn”.To solve this, we will follow these steps −Define a method called getRev(), this will take x as inputret := 0for i in range 0 to 25if x / ... Read More
712 Views
We are given a string containing only digits from 0 to 9, and we need to check whether it is an additive number. An additive number is a string that can form an additive sequence, where each number (starting from the third) is the sum of the previous two. For the sequence to be valid, it must have at least three numbers. Let's look at the example scenarios to understand the problem clearly: Scenario 1 Input: "112358" Output: true Explanation: The digits can form the sequence: 1, 1, 2, 3, 5, 8 Here, 1 + 1 = 2 1 ... Read More
303 Views
Suppose we have an array of citations (The citations are non-negative integers) of a researcher. These numbers are sorted in non-decreasing order. We have to define a function to compute the researcher's h-index. According to the definition of h-index: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each."So if the input is like citations = [0, 1, 4, 5, 6], then the output will be 3, as it indicates that the researcher has five papers, they have got ... Read More
803 Views
Suppose we have an array of citations (The citations are non-negative integers) of a researcher. We have to define a function to compute the researcher's h-index. According to the definition of h-index: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each."So if the input is like citations = [3, 0, 6, 1, 7], then the output will be 3, as it indicates that the researcher has five papers, they have got 3, 0, 6, 1, 7 citations respectively. ... Read More
310 Views
Suppose we have to find the nth ugly number, so we have to define a method that can find it. As we know that the ugly numbers are those numbers, whose prime factors are only 2, 3 and 5. So if we want to find 10th ugly number, that will be 12, as the first few ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12To solve this, we will follow these steps −Make an array v, of size n + 1if n = 1, then return 1two := 2, three = 3 and five = 5, ... Read More
451 Views
Suppose we have an array, there exactly two elements appear once, but others are appearing twice. So we have to define a function, that will find these two numbers. So if the given array is like [1, 2, 3, 1, 5, 2], then the output will be [3, 5].To solve this, we will follow these steps −xor_res := 0for i in range 0 to size of numsxor_res := xor_res XOR nums[i]pos := 0while xor_res AND 2^pos = 0, do, increase pos by 1num1 := 0for i in range 0 to size of nums – 1if nums[i] and 2 ^ pos ... Read More
1K+ Views
Suppose we have a string of numbers and operators, we have to find all possible results from computing all the different possible ways to group the numbers and operators. Here the valid operators are +, - and *. So if the input is like “2*3-4*5”, then the output will be [-34, -14, -10, -10, 10]. This is because −(2*(3-(4*5))) = -34((2*3)-(4*5)) = -14((2*(3-4))*5) = -10(2*((3-4)*5)) = -10(((2*3)-4)*5) = 10To solve this, we will follow these steps −Define a map called a memo.Define a method called solve(). This will take the input string as input.create an array called retif the memo ... Read More
345 Views
Suppose we have one integer array; we have to find those elements that appear more than floor of n/3. Here n is the size of array.So if the input is like [1, 1, 1, 3, 3, 2, 2, 2], then the results will be [1, 2]To solve this, we will follow these steps −first := 0, second := 1, cnt1 := 0, cnt2 := 0, n := size of array numsfor i in range 0 to size of n – 1x := nums[i]if x is first, then increase cnt by 1, otherwise when x is second, then increase cnt2 by ... Read More