Skip to content

Commit 4baea8d

Browse files
committed
Codes updation till Arrays
0 parents  commit 4baea8d

File tree

303 files changed

+2454
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+2454
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.class

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Average of three numbers
2+
3+
You are given three numbers. You need to calculate and print their average value. Draw a flowchart for this process.
4+
Note : You don't need to submit the problem. Just attempt in your notebook and ask doubts if you need help.

1. FlowCharts/2. Check Number.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Check Number
2+
3+
You are given a single number. You need to print one of the following outputs according to the number's nature.
4+
Print 1, if the number is positive
5+
Print -1, if it's negative
6+
Print 0, if it's equal to 0
7+
Draw a flowchart for this process.
8+
Note : You don't need to submit the problem. Just attempt in your notebook and ask doubts if you need help.

1. FlowCharts/3. Valid Triangle.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Valid Triangle
2+
3+
You are given 3 numbers. Each number represents the length of a line. You need to figure out whether these lines can form a valid triangle.
4+
If a valid triangle can be formed, print "Yes", otherwise print "No".
5+
Draw a flowchart for this process
6+
Note : You don't need to submit the problem. Just attempt in your notebook and ask doubts if you need help.

1. FlowCharts/4. Find Product.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Find Product
2+
3+
You are given a single non-negative integer, N. You need to calculate and print N factorial (N!)
4+
N factorial is defined as the product of all integers from 1 to N (both inclusive)
5+
Draw a flowchart for this process
6+
Note : You don't need to submit the problem. Just attempt in your notebook and ask doubts if you need help.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Print Even Numbers
2+
3+
You are given a single positive integer, N. You need to print all even integers that occur between 1 and N (both inclusive).
4+
Draw a flowchart for this process
5+
Note : You don't need to submit the problem. Just attempt in your notebook and ask doubts if you need help.

1. FlowCharts/6. Check Prime.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Check Prime
2+
3+
Draw a flowchart to take a number N from user. And check if that number is prime or not.
4+
Print "Yes" if number is prime, otherwise print "No".
5+
Assume N >= 2.
6+
Note : You don't need to submit the problem. Just attempt in your notebook and ask doubts if you need help.

1. FlowCharts/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I have not uploaded my solutions of Flowchart.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Arrays Sum
2+
3+
Given an array/list(ARR) of length N, you need to find and return the sum of all the elements in the array/list.
4+
Input Format :
5+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
6+
7+
The first line of each test case or query contains an integer 'N' representing the size of the array/list.
8+
9+
Second line contains 'N' single space separated integers representing the elements in the array/list.
10+
Output Format :
11+
For each test case, print the sum of the numbers in the array/list.
12+
13+
Output for every test case will be printed in a separate line.
14+
Constraints :
15+
1 <= t <= 10^2
16+
0 <= N <= 10^5
17+
18+
Time Limit: 1sec
19+
Sample Input 1:
20+
1
21+
3
22+
9 8 9
23+
Sample Output 1:
24+
26
25+
Sample Input 2:
26+
2
27+
5
28+
1 2 3 4 5
29+
3
30+
10 20 30
31+
Sample Output 2:
32+
15
33+
60
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Linear Search
2+
3+
You have been given a random integer array/list(ARR) of size N, and an integer X. You need to search for the integer X in the given array/list using 'Linear Search'.
4+
You have been required to return the index at which X is present in the array/list. If X has multiple occurrences in the array/list, then you need to return the index at which the first occurrence of X would be encountered. In case X is not present in the array/list, then return -1.
5+
'Linear search' is a method for finding an element within an array/list. It sequentially checks each element of the array/list until a match is found or the whole array/list has been searched.
6+
Input format :
7+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
8+
9+
First line of each test case or query contains an integer 'N' representing the size of the array/list.
10+
11+
Second line contains 'N' single space separated integers representing the elements in the array/list.
12+
13+
Third line contains the value of X(integer to be searched in the given array/list)
14+
Output format :
15+
For each test case, print the index at which X is present or -1, otherwise.
16+
17+
Output for every test case will be printed in a separate line.
18+
Constraints :
19+
1 <= t <= 10^2
20+
0 <= N <= 10^5
21+
-2 ^ 31 <= X <= (2 ^ 31) - 1
22+
Time Limit: 1 sec
23+
Sample Input 1:
24+
1
25+
7
26+
2 13 4 1 3 6 28
27+
3
28+
Sample Output 1:
29+
4
30+
Sample Input 2:
31+
2
32+
7
33+
2 13 4 1 3 6 28
34+
9
35+
5
36+
7 8 5 9 5
37+
5
38+
Sample Output 2:
39+
-1
40+
2
Binary file not shown.
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Arrange Numbers in Array
2+
3+
You have been given an empty array(ARR) and its size N. The only input taken from the user will be N and you need not worry about the array.
4+
Your task is to populate the array using the integer values in the range 1 to N(both inclusive) in the order - 1,3,.......4,2.
5+
Note:
6+
You need not print the array. You only need to populate it.
7+
Input Format :
8+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
9+
10+
The first and the only line of each test case or query contains an integer 'N'.
11+
Output Format :
12+
For each test case, print the elements of the arra/listy separated by a single space.
13+
14+
Output for every test case will be printed in a separate line.
15+
Constraints :
16+
1 <= t <= 10^2
17+
0 <= N <= 10^4
18+
19+
Time Limit: 1sec
20+
Sample Input 1 :
21+
1
22+
6
23+
Sample Output 1 :
24+
1 3 5 6 4 2
25+
Sample Input 2 :
26+
2
27+
9
28+
3
29+
Sample Output 2 :
30+
1 3 5 7 9 8 6 4 2
31+
1 3 2
Binary file not shown.
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Swap Alternate
2+
3+
You have been given an array/list(ARR) of size N. You need to swap every pair of alternate elements in the array/list.
4+
You don't need to print or return anything, just change in the input array itself.
5+
Input Format :
6+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
7+
8+
First line of each test case or query contains an integer 'N' representing the size of the array/list.
9+
10+
Second line contains 'N' single space separated integers representing the elements in the array/list.
11+
Output Format :
12+
For each test case, print the elements of the resulting array in a single row separated by a single space.
13+
14+
Output for every test case will be printed in a separate line.
15+
Constraints :
16+
1 <= t <= 10^2
17+
0 <= N <= 10^5
18+
Time Limit: 1sec
19+
Sample Input 1:
20+
1
21+
6
22+
9 3 6 12 4 32
23+
Sample Output 1 :
24+
3 9 12 6 32 4
25+
Sample Input 2:
26+
2
27+
9
28+
9 3 6 12 4 32 5 11 19
29+
4
30+
1 2 3 4
31+
Sample Output 2 :
32+
3 9 12 6 32 4 11 5 19
33+
2 1 4 3
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Find Unique
2+
3+
You have been given an integer array/list(ARR) of size N. Where N is equal to [2M + 1].
4+
Now, in the given array/list, 'M' numbers are present twice and one number is present only once.
5+
You need to find and return that number which is unique in the array/list.
6+
Note:
7+
Unique element is always present in the array/list according to the given condition.
8+
Input format :
9+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
10+
11+
First line of each test case or query contains an integer 'N' representing the size of the array/list.
12+
13+
Second line contains 'N' single space separated integers representing the elements in the array/list.
14+
Output Format :
15+
For each test case, print the unique element present in the array.
16+
17+
Output for every test case will be printed in a separate line.
18+
Constraints :
19+
1 <= t <= 10^2
20+
0 <= N <= 10^3
21+
Time Limit: 1 sec
22+
Sample Input 1:
23+
1
24+
7
25+
2 3 1 6 3 6 2
26+
Sample Output 1:
27+
1
28+
Sample Input 2:
29+
2
30+
5
31+
2 4 7 2 7
32+
9
33+
1 3 1 3 6 6 7 10 7
34+
Sample Output 2:
35+
4
36+
10
Binary file not shown.
Loading
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Find Duplicate
2+
3+
You have been given an integer array/list(ARR) of size N which contains numbers from 0 to (N - 2). Each number is present at least once. That is, if N = 5, the array/list constitutes values ranging from 0 to 3 and among these, there is a single integer value that is present twice. You need to find and return that duplicate number present in the array.
4+
Note :
5+
Duplicate number is always present in the given array/list.
6+
Input format :
7+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
8+
9+
First line of each test case or query contains an integer 'N' representing the size of the array/list.
10+
11+
Second line contains 'N' single space separated integers representing the elements in the array/list.
12+
Output Format :
13+
For each test case, print the duplicate element in the array/list.
14+
15+
Output for every test case will be printed in a separate line.
16+
Constraints :
17+
1 <= t <= 10^2
18+
0 <= N <= 10^3
19+
Time Limit: 1 sec
20+
Sample Input 1:
21+
1
22+
9
23+
0 7 2 5 4 7 1 3 6
24+
Sample Output 1:
25+
7
26+
Sample Input 2:
27+
2
28+
5
29+
0 2 1 3 1
30+
7
31+
0 3 1 5 4 3 2
32+
Sample Output 2:
33+
1
34+
3
Binary file not shown.
Loading
Loading
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Array Intersection
2+
3+
You have been given two integer arrays/list(ARR1 and ARR2) of size M and N, respectively. You need to print their intersection; An intersection for this problem can be defined when both the arrays/lists contain a particular value or to put it in other words, when there is a common value that exists in both the arrays/lists.
4+
Note :
5+
Input arrays/lists can contain duplicate elements.
6+
7+
The intersection elements printed would be in the order they appear in the first array/list(ARR1)
8+
9+
10+
Input format :
11+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
12+
13+
First line of each test case or query contains an integer 'N' representing the size of the first array/list.
14+
15+
Second line contains 'N' single space separated integers representing the elements of the first the array/list.
16+
17+
Third line contains an integer 'M' representing the size of the second array/list.
18+
19+
Fourth line contains 'M' single space separated integers representing the elements of the second array/list.
20+
Output format :
21+
For each test case, print the intersection elements in a row, separated by a single space.
22+
23+
Output for every test case will be printed in a separate line.
24+
Constraints :
25+
1 <= t <= 10^2
26+
0 <= N <= 10^5
27+
0 <= M <= 10^5
28+
Time Limit: 1 sec
29+
Sample Input 1 :
30+
2
31+
6
32+
2 6 8 5 4 3
33+
4
34+
2 3 4 7
35+
2
36+
10 10
37+
1
38+
10
39+
Sample Output 1 :
40+
2 4 3
41+
10
42+
Sample Input 2 :
43+
1
44+
4
45+
2 6 1 2
46+
5
47+
1 2 3 4 2
48+
Sample Output 2 :
49+
2 1 2
50+
Explanation for Sample Output 2 :
51+
Since, both input arrays have two '2's, the intersection of the arrays also have two '2's. The first '2' of first array matches with the first '2' of the second array. Similarly, the second '2' of the first array matches with the second '2' if the second array.
Binary file not shown.
Loading
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Pair Sum
2+
3+
You have been given an integer array/list(ARR) and a number X. Find and return the total number of pairs in the array/list which sum to X.
4+
Note:
5+
Given array/list can contain duplicate elements.
6+
Input format :
7+
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
8+
9+
First line of each test case or query contains an integer 'N' representing the size of the first array/list.
10+
11+
Second line contains 'N' single space separated integers representing the elements in the array/list.
12+
13+
Third line contains an integer 'X'.
14+
Output format :
15+
For each test case, print the total number of pairs present in the array/list.
16+
17+
Output for every test case will be printed in a separate line.
18+
Constraints :
19+
1 <= t <= 10^2
20+
0 <= N <= 10^3
21+
0 <= X <= 10^9
22+
Time Limit: 1 sec
23+
Sample Input 1:
24+
1
25+
9
26+
1 3 6 2 5 4 3 2 4
27+
7
28+
Sample Output 1:
29+
7
30+
Sample Input 2:
31+
2
32+
9
33+
1 3 6 2 5 4 3 2 4
34+
12
35+
6
36+
2 8 10 5 -2 5
37+
10
38+
Sample Output 2:
39+
0
40+
2
41+
42+
43+
Explanation for Input 2:
44+
Since there doesn't exist any pair with sum equal to 12 for the first query, we print 0.
45+
46+
For the second query, we have 2 pairs in total that sum up to 10. They are, (2, 8) and (5, 5).
Binary file not shown.
Loading

0 commit comments

Comments
 (0)