forked from GDSC-JSCOE/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntermediate.txt
83 lines (62 loc) · 3.83 KB
/
Intermediate.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Example :
Solution :
# Python
age=input(int("Age : "))
print(age);
Maintainer : Gaurav-2803
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
1. Write a guessing game where the user has to guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively.
Solution :
2. Write function that reverses a array, preferably in place.
Solution :
3. Write a function that tests whether a string is a palindrome.
Solution :
4. Write a function that tests whether a number is a palindrome.
Solution :
5. Write a function on_all that applies a function to every element of a list. Use it to print the first twenty perfect squares. The perfect squares can be found by multiplying each natural number with itself. The first few perfect squares are 1*1= 1, 2*2=4, 3*3=9, 4*4=16. Twelve for example is not a perfect square because there is no natural number m so that m*m=12.
Solution :
6. Write a function that combines two arrays by alternatingly taking elements, e.g. [a,b,c], [1,2,3] → [a,1,b,2,c,3].
Solution :
7. Write a function that rotates a array by k elements. For example [1,2,3,4,5,6] rotated by two becomes [3,4,5,6,1,2]. Try solving this without creating a copy of the array. How many swap or move operations do you need?
Solution :
8. Write a function that takes a number and returns a array of its digits. So for 2342 it should return [2,3,4,2].
Solution :
9. Write functions that add, subtract, and multiply digits of two numbers.
Solution :
10. Implement binary search.
Solution :
11. Write a function that takes a array of strings an prints them, one per line, in a rectangular frame. For example the list ["Hello", "World", "in", "a", "frame"] gets printed as:
*********
* Hello *
* World *
* in *
* a *
* frame *
*********
Solution :
12. Print the following pattern without using print in-built function.
i. ii. iii. iv.
* *** * ***
** ** ** **
*** * *** *
v. ii. iii. iv.
1 123 1 123
23 45 23 45
456 5 456 6
Solution :
13. Convert Age -> Days (Consider leap years in between) take year of birth as input also.
Solution :
14. Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers. Note. (side1 + side2) - 1 = maximum range of third edge.
Solution :
15. Write a function that takes number K where is smaller than size of array, we need to find the Kth smallest and largest elementin the given array.It is given that all array elements are not distinct and If not present return -1.
Solution :
16. Write a function that sort array of 0s, 1s & 2s (inbuilt sort functions are not allowed)
Solution :
17. Given Unsorted array check whether elements are in Arithmetic Progression (Differnce between every 2 consecutive is same) if not return -1.
Example : 1,2,3,4,5 are in A.P
Solution :
18. Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity.
Solution :
19. Given a string S,of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line.
I/P -> Gaurav O/P -> Gua arv
Solution :