GeeksforGeeks

yesterday at 16:52.
Facebook

[ Geeksforgeeks.org Link ]

Input : arr[] = [3, 5, 100, 101, 102]

K = 3

Output : 2

Possible subsets of K-length with

their differences are,

[3 5 100] max min diff is (100 - 3) = 97

[3 5 101] max min diff is (101 - 3) = 98

[3 5 102] max min diff is (102 - 3) = 99

[3 100 101] max min diff is (101 - 3) = 98

[3 100 102] max min diff is (102 - 3) = 99

[3 101 102] max min diff is (102 -...

View details ⇨
### Minimum difference between max and min of all K-size subsets - GeeksforGeeks

Input : arr[] = [3, 5, 100, 101, 102]

K = 3

Output : 2

Possible subsets of K-length with

their differences are,

[3 5 100] max min diff is (100 - 3) = 97

[3 5 101] max min diff is (101 - 3) = 98

[3 5 102] max min diff is (102 - 3) = 99

[3 100 101] max min diff is (101 - 3) = 98

[3 100 102] max min diff is (102 - 3) = 99

[3 101 102] max min diff is (102 -...

View details ⇨

geeksforgeeks.org

GeeksforGeeks

yesterday at 15:21.
Facebook

[ Geeksforgeeks.org Link ]

Input : 1775

Output : 8

Binary representation of 1775 is 11011101111.

After flipping the highlighted bit, we get

consecutive 8 bits.

Input : 12

Output : 3

Input : 15

Output : 5
### Find longest sequence of 1's in binary representation with one flip - GeeksforGeeks

Input : 1775

Output : 8

Binary representation of 1775 is 11011101111.

After flipping the highlighted bit, we get

consecutive 8 bits.

Input : 12

Output : 3

Input : 15

Output : 5

geeksforgeeks.org

GeeksforGeeks

yesterday at 07:15.
Facebook

[ Geeksforgeeks.org Link ]

Input : 2317

Output : 1 2

Explanation : Left and right side numbers of index

point 1 are 2 and 17 respectively and

both are primes. Left and right side

numbers of index point 2 are 23 and 7

respectively and both are prime.

Input : 2418

Output : -1

Explanation : No index point has both the left

...

View details ⇨
### Prime points (Points that split a number into two primes) - GeeksforGeeks

Input : 2317

Output : 1 2

Explanation : Left and right side numbers of index

point 1 are 2 and 17 respectively and

both are primes. Left and right side

numbers of index point 2 are 23 and 7

respectively and both are prime.

Input : 2418

Output : -1

Explanation : No index point has both the left

...

View details ⇨

geeksforgeeks.org

GeeksforGeeks

yesterday at 05:24.
Facebook

[ Geeksforgeeks.org Link ]

Input : S = "abcab"

Output : 7

There are 15 substrings of "abcab"

a, ab, abc, abca, abcab, b, bc, bca

bcab, c, ca, cab, a, ab, b

Out of the above substrings, there

are 7 substrings : a, abca, b, bcab,

c, a and b.

Input : S = "aba"

Output : 4

The substrings are a, b, aa and aba
### Count substrings with same first and last characters - GeeksforGeeks

Input : S = "abcab"

Output : 7

There are 15 substrings of "abcab"

a, ab, abc, abca, abcab, b, bc, bca

bcab, c, ca, cab, a, ab, b

Out of the above substrings, there

are 7 substrings : a, abca, b, bcab,

c, a and b.

Input : S = "aba"

Output : 4

The substrings are a, b, aa and aba

geeksforgeeks.org

GeeksforGeeks

yesterday at 03:23.
Facebook

[ Geeksforgeeks.org Link ]

Given an integer n. Find politeness of number n. Politeness of a number is defined as the number of ways it can be expressed as the sum of consecutive integers.

Input: n = 15

Output: 3

Explanation:

There are only three ways to express

15 as sum of consecutive integers i.e.,

15 = 1 + 2 + 3 + 4 + 5

15 = 4 + 5 + 6

15 = 7 + 8

Hence answer is 3

Input: n = 9;

Output: ...

View details ⇨
### Find politeness of a number - GeeksforGeeks

Given an integer n. Find politeness of number n. Politeness of a number is defined as the number of ways it can be expressed as the sum of consecutive integers.

Input: n = 15

Output: 3

Explanation:

There are only three ways to express

15 as sum of consecutive integers i.e.,

15 = 1 + 2 + 3 + 4 + 5

15 = 4 + 5 + 6

15 = 7 + 8

Hence answer is 3

Input: n = 9;

Output: ...

View details ⇨

geeksforgeeks.org

GeeksforGeeks

03/23/2017 at 16:54.
Facebook

[ Geeksforgeeks.org Link ]

Given three integers, print them in sorted order without using if condition.

Input : a = 3, b = 2, c = 9

Output : 2 3 9

Input : a = 4, b = 1, c = 9

Output : 1 4 9
### Sort 3 Integers without using if condition or using only max() function - GeeksforGeeks

Given three integers, print them in sorted order without using if condition.

Input : a = 3, b = 2, c = 9

Output : 2 3 9

Input : a = 4, b = 1, c = 9

Output : 1 4 9

geeksforgeeks.org

GeeksforGeeks

03/23/2017 at 15:06.
Facebook

[ Geeksforgeeks.org Link ]

Given a string consisting of some numbers, not separated by any separator. The numbers are positive integers and the sequence increases by one at each number except the missing number. The task is to find the missing number. The numbers will have no more than six digits. Print -1 if input sequence is not valid.

Examples:

Input : 89101113

Output : 12

Input :...

View details ⇨
### Find the missing number in a string of numbers with no separator - GeeksforGeeks

Given a string consisting of some numbers, not separated by any separator. The numbers are positive integers and the sequence increases by one at each number except the missing number. The task is to find the missing number. The numbers will have no more than six digits. Print -1 if input sequence is not valid.

Examples:

Input : 89101113

Output : 12

Input :...

View details ⇨

geeksforgeeks.org

GeeksforGeeks

03/23/2017 at 13:43.
Facebook

[ Geeksforgeeks.org Link ]

One of the most asked interview questions
### Median in a stream | Practice | GeeksforGeeks

One of the most asked interview questions

practice.geeksforgeeks.org

GeeksforGeeks

03/23/2017 at 10:44.
Facebook

Books ⋅ Literature
### Technical Scripter by GeeksforGeeks

EVENT - facebook.com

GeeksforGeeks

03/23/2017 at 07:50.
Facebook

[ Geeksforgeeks.org Link ]

Given two numbers x and n, find number of ways x can be expressed as sum of n-th power of unique natural numbers.

Input : x = 10, n = 2

Output : 1

Explanation: 10 = 12 + 32,

Hence total 1 possibility

Input : x = 100, n = 2

Output : 3

Explanation: 100 = 102

OR 62 + 82

OR 12 + 32 + 42 + 52 + 72

Hence total 3 possibilities
### Find ways an Integer can be expressed as sum of n-th power of unique natural numbers - GeeksforGeeks

Given two numbers x and n, find number of ways x can be expressed as sum of n-th power of unique natural numbers.

Input : x = 10, n = 2

Output : 1

Explanation: 10 = 12 + 32,

Hence total 1 possibility

Input : x = 100, n = 2

Output : 3

Explanation: 100 = 102

OR 62 + 82

OR 12 + 32 + 42 + 52 + 72

Hence total 3 possibilities

geeksforgeeks.org

GeeksforGeeks

03/23/2017 at 06:00.
Facebook

[ Geeksforgeeks.org Link ]

Given an array, we need to modify values of this array in such a way that sum of absolute differences between two consecutive elements is maximized. If the value of an array element is X, then we can change it to either 1 or X.

Examples:

Input : arr[] = [3, 2, 1, 4, 5]

Output : 8

We can modify above array as,

Modified arr[] = [3, 1, 1, 4, 1]

Sum of differences =...

View details ⇨
### Modify array to maximize sum of adjacent differences - GeeksforGeeks

Given an array, we need to modify values of this array in such a way that sum of absolute differences between two consecutive elements is maximized. If the value of an array element is X, then we can change it to either 1 or X.

Examples:

Input : arr[] = [3, 2, 1, 4, 5]

Output : 8

We can modify above array as,

Modified arr[] = [3, 1, 1, 4, 1]

Sum of differences =...

View details ⇨

geeksforgeeks.org

GeeksforGeeks

03/23/2017 at 03:03.
Facebook

[ Geeksforgeeks.org Link ]

Input: n = 16

Output: yes

Explanation:

16 is a superperfect number as σ(16) = 1 + 2 + 4 + 8 + 16 = 31,

and σ(31) = 1 + 31 = 32,

thus σ(σ(16)) = 32 = 2 × 16.

Input: n = 8

Output: no

Explanation:

σ(8) = 1 + 2 + 4 + 8 = 15

and σ(15) = 1 + 3 + 5 + 15 = 24

thus ( σ(σ(8)) = 24 ) ≠ (2 * 8 = 26)
### Superperfect Number - GeeksforGeeks

Input: n = 16

Output: yes

Explanation:

16 is a superperfect number as σ(16) = 1 + 2 + 4 + 8 + 16 = 31,

and σ(31) = 1 + 31 = 32,

thus σ(σ(16)) = 32 = 2 × 16.

Input: n = 8

Output: no

Explanation:

σ(8) = 1 + 2 + 4 + 8 = 15

and σ(15) = 1 + 3 + 5 + 15 = 24

thus ( σ(σ(8)) = 24 ) ≠ (2 * 8 = 26)

geeksforgeeks.org

GeeksforGeeks

03/22/2017 at 18:34.
Facebook

[ Geeksforgeeks.org Link ]

DatagramSockets are Java’s mechanism for network communication via UDP instead of TCP. Java provides DatagramSocket to communicate over UDP instead of TCP. It is also built on top of IP. DatagramSockets can be used to both send and receive packets over the Internet.
### Working with UDP DatagramSockets in Java - GeeksforGeeks

DatagramSockets are Java’s mechanism for network communication via UDP instead of TCP. Java provides DatagramSocket to communicate over UDP instead of TCP. It is also built on top of IP. DatagramSockets can be used to both send and receive packets over the Internet.

geeksforgeeks.org