forked from hackerearthclub/CODE2RACE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4fa35c
commit 139844f
Showing
8 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Program to find the product of ASCII values of characters in a string | ||
Given a string str. The task is to find the product of ASCII values of characters in the string. | ||
|
||
Examples: | ||
|
||
Input : str = "IS" | ||
Output : 6059 | ||
73 * 83 = 6059 | ||
|
||
Input : str = "GfG" | ||
Output : 514182 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Chef has invited his friends on his birthday party. There are total N friends that are coming at his home. You are given the arriving and leaving time of each friend and Q queries. Each Query consists of an integer t, you have to output the number of friends that are present at time t at Chef's home. | ||
|
||
Input | ||
The first line contains T, the number of testcases. | ||
|
||
The first line of each testcase contain two space separated integers N and Q, then follow N lines containing two space separated integers ai bi, the arriving and leaving time of ith friend respectively. | ||
|
||
Next Q lines contains a single integer t asking the number of friends at Chef's house present at time t. | ||
|
||
Output | ||
For each query, output the required answer in a new line. | ||
|
||
Constraints | ||
1 ≤ T ≤ 10 | ||
1 ≤ N ≤ 100000 | ||
1 ≤ Q ≤ 100000 | ||
1 ≤ ai ≤ bi ≤ 100000 | ||
1 ≤ t ≤ max of all bi | ||
Example | ||
Input: | ||
1 | ||
3 3 | ||
1 2 | ||
2 2 | ||
2 3 | ||
1 | ||
2 | ||
3 | ||
|
||
Output: | ||
1 | ||
3 | ||
1 |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
LCM of given array elements | ||
Given an array of n numbers, find LCM of it. | ||
|
||
Input : {1, 2, 8, 3} | ||
Output : 24 | ||
|
||
Input : {2, 7, 3, 9, 4} | ||
Output : 252 | ||
|
||
|
||
GCD of more than two (or array) numbers | ||
Given an array of numbers, find GCD of the array elements. In a previous post we find GCD of two number. | ||
|
||
Examples: | ||
|
||
Input : arr[] = {1, 2, 3} | ||
Output : 1 | ||
|
||
Input : arr[] = {2, 4, 6, 8} | ||
Output : 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Length of largest sub-array having primes strictly greater than non-primes | ||
Given an array ‘arr’ of length ‘n’. The task is to find the largest contiguous sub-array having the count of prime numbers strictly greater than the count of non-prime numbers. | ||
|
||
Examples: | ||
|
||
Input: arr[] = {4, 7, 4, 7, 11, 5, 4, 4, 4, 5} | ||
Output: 9 | ||
|
||
Input: arr[] = { 1, 9, 3, 4, 5, 6, 7, 8 } | ||
Output: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Sum of all nodes in a doubly linked list divisible by a given number K | ||
Given a doubly linked list containing N nodes and given a number K. The task is to find the sum of all such nodes which are divisible by K. | ||
|
||
Examples: | ||
|
||
Input: List = 15 <=> 16 <=> 10 <=> 9 <=> 6 <=> 7 <=> 17 | ||
K = 3 | ||
Output: Sum = 30 | ||
|
||
Input: List = 5 <=> 3 <=> 6 <=> 8 <=> 4 <=> 1 <=> 2 <=> 9 | ||
K = 2 | ||
Output: Sum = 20 | ||
Approach: The idea is to traverse the doubly linked list and check the nodes one by one. If a node’s value is divisible by K then add that node value to sum otherwise continue this process while the end of the list is not reached. |