0% found this document useful (0 votes)
6 views

problems

The document contains a series of programming practice problems covering various topics such as operators, control flow, arrays, and functions. Each problem includes specific tasks for users to implement, along with examples of input and expected output. The problems are designed to enhance programming skills and understanding of basic concepts.

Uploaded by

mfraire90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

problems

The document contains a series of programming practice problems covering various topics such as operators, control flow, arrays, and functions. Each problem includes specific tasks for users to implement, along with examples of input and expected output. The problems are designed to enhance programming skills and understanding of basic concepts.

Uploaded by

mfraire90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Practice Problems

Table of Contents
Operators and Basics .............................................................................................................................. 1
Controlling Flow of Execution ............................................................................................................... 4
Arrays .................................................................................................................................................... 10
Functions ................................................................................................................................................ 19
Advanced Problems .............................................................................................................................. 20

Operators and Basics


1. Write a program which prints – Hello World!!
2. Write a program which asks the user for an integer and outputs twice the value
A. Example
i. Input: Please enter a number: 42
ii. Output: The number 84 is double your input number 42
3. Write a program which asks the user for a floating-point number and outputs twice the value
A. Example
i. Input: Please enter a number: 42.69
ii. Output: The number 85.38 is double your input number 42.69
4. Write a program that outputs the Boolean for equality of the comparison of two user input
integers
A. Example 1
i. Input:
• Please enter first number: 42
• Please enter second number: 42
ii. Output:
• Result of comparison: 1
B. Example 2
i. Input:
• Please enter first number: 42
• Please enter second number: 84
ii. Output:
• Result of comparison: 0
5. Write a program that takes two integers as input and outputs the results of sum, differences,
product and divisions of the numbers
A. Example
i. Input:
• Please enter first number (X): 4
• Please enter second number (Y): 2
ii. Output
• Sum of numbers (X + Y): 6
• Difference of numbers (X – Y): 2
• Difference of numbers (Y – X): -2
• Product of numbers (X * Y): 8
• Division of numbers (X \ Y): 2
• Division of numbers (Y \ X): 0
6. Write a program that takes two integers as input and outputs the remainder of dividing the two
numbers
A. Example
i. Input:
• Please enter first number (X): 4
• Please enter second number (Y): 3
ii. Output:
• Remainder (X % Y): 1
7. Write a program that takes two floating-point numbers and outputs the results of logical operators
comparing the two
A. Example
i. Input
• Please enter first number (X): 4
• Please enter second number (Y): 2
ii. Output
• Equality check (X == Y): 0
• Non-equality check (X != Y): 1
• Less than check (X < Y): 0
• Greater than check (X > Y): 1
• Less than or equal check (X <= Y): 0
• Greater than or equal (X >= Y): 1

8. Given two numbers, return true if the sum of both numbers is less than 100. Otherwise
return false.
A. Example
i. Input:
• Please enter first number: 44
• Please enter second number: 37
ii. Output:
• Sum less than 100: True
9. Write a program that takes three floating point numbers, the width and height of a rectangle, and
the radius of a circle and returns true if the rectangle can fit inside the circle.
A. Example
i. Input:
• Please enter width of rectangle: 8
• Please enter height of rectangle: 6
• Please enter radius of circle: 5
ii. Output:
• Rectangle fits inside circle: True
10. Write a program that takes a floating-point value in minutes and displays the corresponding
number if seconds as the closest integer value
A. Example
i. Input:
• Please enter minutes: 4.21
ii. Output:
• Time in seconds: 252
11. Write a program that takes a floating-point value in hours and displays the corresponding number
if seconds as the closest integer value
A. Example
i. Input:
• Please enter hours: 4.21
ii. Output:
• Time in seconds: 15156
12. Write a program that takes a floating-point number as input temperature in Fahrenheit and
converts it to Celsius.
A. Example
i. Input
• Please enter temperature in Fahrenheit: 89.6
ii. Output
• Temperature 89.6F is 32-degree Celsius
13. Write a program that takes a floating-point number as input temperature in Celsius and converts it
to Fahrenheit.
A. Example
i. Input
• Please enter temperature in Celsius: 32
ii. Output
• Temperature 32C is 89.6-degree Fahrenheit
14. Write a program for a farmer who wants to count the total number of legs of all the farm animals.
Assuming that the program works for three types of animals, chickens (2 legs), cows (4 legs) and
pigs (4 legs).
A. Example
i. Input
• Please enter number of chickens: 42
• Please enter number of cows: 2
• Please enter number of pigs: 4
ii. Output
• Total number of legs for the animals: 108
15. Write a program that asks the user for two floating point numbers (say a and b) and
prints out the value of (a + b) squared
A. Example
i. Input
• Please enter first number: 7.9
• Please enter second number: 2.1
ii. Output
• Square of (7.9 + 2.1) is 100
16. Write a program that asks the user for two floating point numbers (say a and b) and
prints out the value of (a3 + b3 + 3a2y + 3ab2)
A. Example
i. Input
• Please enter first number: 7.9
• Please enter second number: 2.1
ii. Output
• Result: 1000
17. Write a program that takes an integer number prints the square of the number.
A. Example
i. Input
• Please enter number: 8
ii. Output
• Square of 8 is 64

Controlling Flow of Execution


18. Write a program that takes two integer numbers (say N1 and N2) prints the number N1 to the
power of N2. (Do not use any libraries or predefined functions).
A. Example
i. Input
• Please enter number: 8
• Please enter number: 3
ii. Output
• Result of 8 raised to the power of 3: 512
19. Write a program that asks the user for 3 numbers and prints out all permutations of those numbers
A. Example
i. Input
• Enter First number: 4
• Enter Second number: 2
• Enter Third number: 6
ii. Output (Your ordering of output might vary, as long as you cover all cases)
• The permutations are
• 426
• 462
• 246
• 264
• 642
• 624
20. Write a program which asks the user for an integer number and counts down from that number to
one.
A. Example
i. Input
• Please enter number: 6
ii. Output
• Counting down
• Counter is 6
• Counter is 5
• Counter is 4
• Counter is 3
• Counter is 2
• Counter is 1
21. Write a program which asks the user for an integer number and counts up to that number from
one.
B. Example
iii. Input
• Please enter number: 6
iv. Output
• Counting up
• Counter is 1 of 6
• Counter is 2 of 6
• Counter is 3 of 6
• Counter is 4 of 6
• Counter is 5 of 6
• Counter is 6 of 6
22. Write a program which asks the user for an integer number and prints out whether the input
number is positive or negative. (Consider 0 to be positive)
A. Example 1
i. Input:
• Please enter number: 42
ii. Output:
• Number is positive
B. Example 2
i. Input:
• Please enter number: -9
ii. Output:
• Number is negative
23. Write a program which asks the user for an integer number and prints out whether the input
number is positive or negative. (Consider 0 to be a special case)
A. Example 1
i. Input:
• Please enter number: 0
ii. Output:
• Zero is neither positive nor negative
B. Example 2
i. Input:
• Please enter number: -9
ii. Output:
• Number is negative
24. Write a program which asks the user for an integer number and prints out whether the input
number is a multiple of 7.
A. Example 1
i. Input:
• Please enter number: -49
ii. Output:
• Number is a multiple of seven
B. Example 2
i. Input:
• Please enter number: -9
ii. Output:
• Number is not a multiple of seven
25. Write a program which asks the user for two integer numbers (say N1 and N2) and prints out
whether the input number N1 is a multiple of N2.
A. Example 1
i. Input:
• Please enter first number: 49
• Please enter second number: 7
ii. Output:
• Number 49 is a multiple of 7
B. Example 2
i. Input:
• Please enter first number: 40
• Please enter second number: 3
ii. Output:
• Number 40 is not a multiple of 3
26. Write a program which asks the user for an integer number and prints out whether the input
number is even or odd.
A. Example
i. Input:
• Please enter number: 42
ii. Output:
• Number is even
27. Write a program that asks the user for an integer number and prints a pattern.
A. Example
i. Input
• Please enter number: 5
ii. Output
• ....*
...**
..***
.****
*****
❖ Note that the last row prints 5 *s as per user input
28. Write a program that asks the user for an integer number and prints a pattern.
A. Example
i. Input
• Please enter number: 5
ii. Output
• ....*
...**
..***
.****
*****
.****
..***
...**
....*
❖ Note that the middle row prints 5 *s as per user input
29. Write a program that asks the user for a positive integer N (Handle cases when the user provides a
negative number) and
A. If input number N is 0 <= N <= 9, prints out lowercase English word corresponding to
the number
B. If input number N > 9, prints “Greater than 9”
You would need to hard code the words for each digit up to nine
a. Example 1
i. Input
• Please enter number: 9
ii. Output
• nine
b. Example 2
i. Input
• Please enter number: 42
ii. Output
• Number greater than nine
30. Write a program that asks the user for a positive integer N (Handle cases when the user provides a
negative number) and
A. If input number N is 0 <= N <= 9, prints out lowercase English word corresponding to
the number
B. If input number N > 9, prints out lowercase English word corresponding to each digit
You would need to hard code the words for each digit up to nine
a. Example 1
i. Input
• Please enter number: 9
ii. Output
• nine
b. Example 2
i. Input
• Please enter number: 420
ii. Output
• four two zero
31. Write a program which asks the user for an integer number (say N) and prints out the sum of all
numbers up to N using a loop. (1 + 2 + 3 + 4 + 5 + 6 + ... + N)
A. Example
i. Input:
• Please enter number: 42
ii. Output:
• Sum of all numbers up to 42: 903
32. Write a program which asks the user for an integer number (say N) and prints out the sum of all
numbers up to N using the formula N*(N+1)/2
A. Example
i. Input:
• Please enter number: 3
ii. Output:
• Sum of all numbers up to 3: 6
33. Write a program which asks the user for an integer number (say N) and prints out the sum of all
even numbers up to N using a loop. (2 + 4 + 6 + … )
A. Example
i. Input:
• Please enter number: 4
ii. Output:
• Sum of all even numbers up to 4: 6
34. Write a program which asks the user for an integer number (say N) and prints out the sum of all
odd numbers up to N using a loop. (1 + 3 + 5 + … )
A. Example
i. Input:
• Please enter number: 10
ii. Output:
• Sum of all odd numbers up to 10: 25
35. Write a program which asks the user for an integer number (say N) and prints out the factorial of
N. (1 * 2 * 3 * … * N)
A. Example
i. Input:
• Please enter number: 4
ii. Output:
• Factorial of 4: 24
36. Write a program which asks the user for 5 integer numbers and returns two numbers which form
the largest sum.
A. Example
i. Input
• Please enter number 1: 5
• Please enter number 2: 3
• Please enter number 3: 10
• Please enter number 4: 4
• Please enter number 5: 1
ii. Output
• Numbers 5 and 10 form the largest sum: 15
37. Write a program which asks the user for an integer number and returns to reverse integer.
A. Example
i. Input
• Please enter number: 492
ii. Output
• Reverse of number: 294
38. Write a program in order to determine whether an integer is a palindrome. An
integer is a palindrome when it reads the same backward as forward.
A. Example 1
i. Input
• Please enter number: 121
ii. Output
• The number is a palindrome
B. Example 2
i. Input
• Please enter number: 42
ii. Output
• The number is not a palindrome
39. Write a program which determines if an input integer is a prime number.
A. Example 1
i. Input
• Please enter number: 17
ii. Output
• The number is a prime
B. Example 2
i. Input
• Please enter number: 42
ii. Output
• The number is not a prime
40. Write a program that prints out all prime numbers up to some input number.
A. Example 1
iii. Input
• Please enter number: 20
iv. Output
• Primes:
• 2
• 3
• 5
• 7
• 11
• 13
• 17
• 19
41. Write a program which computes the average of input positive integers. Your code should ask the
user for input until a negative number is provided.
A. Example 1
i. Input
• Please enter number 1: 10
• Please enter number 2: 5
• Please enter number 3: 1
• Please enter number 4: 3
• Please enter number 5: 2
• Please enter number 6: 42
• Please enter number 7: 21
• Please enter number 8: 7
• Please enter number 9: 9
• Please enter number 10: 24
• Please enter number 11: -1
ii. Output
• The average of numbers is: 12.4
B. Example 2
i. Input
• Please enter number 1: 1
• Please enter number 2: 2
• Please enter number 3: 3
• Please enter number 4: 4
• Please enter number 5: -5
ii. Output
• The average of numbers is: 2.5

Arrays
42. Write a C++ program to find the largest element of a given array of integers
A. Example 1
i. Input
• Please enter array size: 7
• Please enter element 0: -9
• Please enter element 1: -5
• Please enter element 2: 2
• Please enter element 3: 10
• Please enter element 4: 6
• Please enter element 5: 7
• Please enter element 6: 8
ii. Output
• 10
43. Write a C++ program to find the most occurring element in an array of integers.
A. Example 1
i. Input
• Please enter array size: 7
• Please enter element 0: -9
• Please enter element 1: -5
• Please enter element 2: 2
• Please enter element 3: 10
• Please enter element 4: -9
• Please enter element 5: 7
• Please enter element 6: -9
ii. Output
• -9
44. Write a program to find missing elements in the set of numbers from 1 to 6, in a user given array
A. Example 1
i. Input
• Please enter array size: 10
• Please enter element 0: 2
• Please enter element 1: 4
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 6
• Please enter element 5: 6
• Please enter element 6: 1
• Please enter element 7: 1
• Please enter element 8: 4
• Please enter element 9: 2
ii. Output
• 3
• 5
45. Write a C++ program to separate even and odd numbers of an array of integers. Put all even
numbers first, and then odd numbers.
A. Example 1
i. Input
• Please enter array size: 10
• Please enter element 0: 2
• Please enter element 1: 5
• Please enter element 2: 9
• Please enter element 3: 10
• Please enter element 4: 16
• Please enter element 5: 16
• Please enter element 6: 18
• Please enter element 7: 7
• Please enter element 8: 3
• Please enter element 9: 2
ii. Output
• [2, 10, 16, 16, 18, 2, 5, 9, 7, 3]
46. Write a program that breaks an integer down to its corresponding digits and prints the digits in an
array. Assume a maximum integer 99999
A. Example 1
i. Input
• Please enter integer: 95923
ii. Output
• [9, 5, 9, 2, 3]
47. Write a C++ program to count the number of occurrences of given number in an Unsorted array
of integers.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
• Please enter number to search for: 6
ii. Output
• 3
48. Write a C++ program to count the number of occurrences of given number in a sorted array of
integers.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 4
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 6
• Please enter element 5: 6
• Please enter number to search for: 6
ii. Output
• 3
49. Write a C++ program to find and print all unique elements of a given array of integers.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
ii. Output
• [2, 6, 4]
50. Given an array of integers and a value, remove all instances of that value and return the new
length.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
• Please enter number to remove: 4
ii. Output
• 4
51. Given a sorted array, remove the duplicates such that each element appears only once.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 4
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 6
• Please enter element 5: 6
ii. Output
• [2, 4, 6]
52. Write a program to find the cumulative sum of a given array.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
ii. Output
• [2, 8, 12, 18, 22, 28]
53. Write a program to find the reverse cumulative sum of a given array
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
ii. Output
• [28, 26, 20, 16, 10, 6]
54. Write a program to search for an element in an array and print the index of first occurrence.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
• Please enter the element to search for: 4
ii. Output
• 2
55. Insert an element in an array at given index and print new array.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
• Please enter element to be inserted: 5
• Please enter index to be inserted at: 3
ii. Output
• [2, 6, 4, 5, 6, 4, 6]
56. Rotate a matrix clockwise
57. Transpose a matrix
58. Given an integer array, find the contiguous subarray (containing at least one number) which has
the largest sum and return its sum.
A. Example:
i. Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4],
ii. Output: 6
• Explanation: [4, -1, 2, 1] has the largest sum = 6.
59. Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral
order.
A. Example:
i. Input:
• [
• [ 1, 2, 3 ],
• [ 4, 5, 6 ],
• [ 7, 8, 9 ]
• ]
ii. Output: [1,2,3,6,9,8,7,4,5]
60. Given a set of distinct integers, return all possible subsets (the power set). Note: The solution set
must not contain duplicate subsets.
A. Example:
i. Input:
• [1,2,3]
ii. Output:
• [
• [3],
• [1],
• [2],
• [1,2,3],
• [1,3],
• [2,3],
• [1,2],
• []
• ]
61. Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and
return its area.
A. Example:
i. Input:
• [
• [1, 0, 1, 0, 0],
• [1,0, 1, 1, 1],
• [1, 1, 1, 1, 1],
• [1, 0, 0, 1, 0]
• ]
ii. Output: 6
62. Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's
triangle, each number is the sum of the two numbers directly above it.
A. Example:
i. Input: 5
ii. Output:
• [
• [1],
• [1,1],
• [1,2,1],
• [1,3,3,1],
• [1,4,6,4,1]
• ]
63. Given an array, write a function to move all 0's to the end of it while maintaining the relative order of
the non-zero elements.
A. Example:
i. Input: [0,1,0,3,12]
ii. Output: [1,3,12,0,0]
64. Given a non-empty array of integers, return the third maximum number in this array. If it does not
exist, return the maximum number.
A. Example 1:
i. Input: [3, 2, 1]
ii. Output: 1
• Explanation: The third maximum is 1.
B. Example 2:
i. Input: [1, 2]
ii. Output: 2
• Explanation: The third maximum does not exist, so the maximum (2) is
returned instead.
C. Example 3:
i. Input: [2, 2, 3, 1]
ii. Output: 1
• Explanation: Note that the third maximum here means the third
maximum distinct number. Both numbers with value 2 are both
considered as second maximum.
65. Given a binary array, find the maximum number of consecutive 1s in this array.
A. Example 1:
i. Input: [1, 1, 0, 1, 1, 1]
ii. Output: 3
• Explanation: The first two digits or the last three digits are consecutive
1s. The maximum number of consecutive 1s is 3.
66. Partition array into two separate arrays, given index of partition
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
• Please enter index of partition: 2
ii. Output
• [2, 6]
• [4, 6, 4, 6]
67. Print out nested array. A zero-indexed array A of length N contains all integers from 0 to N-1.
Print the array as {A[i], A[A[i]], A[A[A[i]]], ... } for 10 steps.
A. Example:
i. Input: A = [5,4,0,3,1,6,2]
ii. Output: {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0}
68. Write a program that asks the user for an integer pivot, and partitions an array such that all
elements smaller than pivot are in one array, while all elements larger or equal to pivot are in
another array.
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 7
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 3
• Please enter pivot: 5
ii. Output
• [2, 4, 4, 3]
• [7, 6]
69. Write a program to filter out elements from an array larger than user input number
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
• Please enter filter value: 3
ii. Output
• [6, 4, 6, 4, 6]
70. Write a program to add user input value to every element in array
A. Example 1
i. Input
• Please enter array size: 6
• Please enter element 0: 2
• Please enter element 1: 6
• Please enter element 2: 4
• Please enter element 3: 6
• Please enter element 4: 4
• Please enter element 5: 6
• Please enter element to be added: 3
ii. Output
• [5, 9, 7, 9, 7, 9]
71. Write a program to generate Collatz sequence for user given number.
72. Write a program to add two user input matrices.
73. Write a program to subtract two user input matrices.
74. Write a program to element wise divide two matrices.
75. Write a program to print the first 20 Fibonacci numbers in reverse.
76. Write a program to concatenate two arrays.
77. Write a program to concatenate two matrices along x axis.
78. Write a program to save diagonal of matrix as an array.
79. A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now
given an M x N matrix, print True if and only if the matrix is Toeplitz.
A. Example 1:
i. Input:
• matrix = [
• [1, 2, 3, 4],
• [5, 1, 2, 3],
• [9, 5, 1, 2]
• ]
ii. Output: True
• Explanation:
• In the above grid, the diagonals are:
• "[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]". In each diagonal all
elements are the same, so the answer is True.
80. A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row,
column, and both diagonals all have the same sum. Check if a 3 x 3 matrix is a magic square.
A. Example 1:
i. Input:
• matrix = [
• [4, 3, 8],
• [9, 5, 1],
• [2, 7, 6]
• ]
ii. Output: True
81. In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty.
There is at least one empty seat, and at least one person sitting. Alex wants to sit in the seat such
that the distance between him and the closest person to him is maximized. Return that maximum
distance to closest person.
A. Example 1:
i. Input: [1, 0, 0, 0, 1, 0, 1]
ii. Output: 2
• Explanation:
• If Alex sits in the second open seat (seats[2]), then the closest person has
distance 2.
• If Alex sits in any other open seat, the closest person has distance 1.
• Thus, the maximum distance to the closest person is 2.
82. Find array advantage. Given two arrays A and B of equal size, the advantage of A with respect to
B is the number of indices i for which A[i] > B[i].
83. Given a fixed length array of integers, duplicate each occurrence of zero, shifting the remaining
elements to the right. Note that elements beyond the length of the original array are not written.
A. Example 1:
i. Input: [1, 0, 2, 3, 0, 4, 5, 0]
ii. Output:[1, 0, 0, 2, 3, 0, 0, 4]
84. Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that
occurs more than 25% of the time. Return that integer.
A. Example 1:
i. Input: [1, 2, 2, 6, 6, 6, 6, 7, 10]
ii. Output: 6
85. Given a date, return the corresponding day of the week for that date. The input is given as three
integers representing the day, month and year respectively. Return the answer as one of the
following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday"}.
A. Example 1:
i. Input: day = 31, month = 8, year = 2019
ii. Output: "Saturday"
86. You are given an array of coordinates, coordinates[i] = [x, y], where [x, y] represents the
coordinate of a point. Check if these points make a straight line in the XY plane.
A. Example 1:
i. Input: coordinates = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]
ii. Output: True
87. Write a program to find all odd elements in a matrix.
88. Write a program to row wise rotate matrix by k elements.
89. Given a matrix representing a Tic Tac Toe game, find Winner on a Tic Tac Toe Game
90. Given an array of integers, return how many of them contain an even number of digits.
A. Example 1:
i. Input: [12, 345, 2, 6, 7896]
ii. Output: 2
• Explanation:
• 12 contains 2 digits (even number of digits).
• 345 contains 3 digits (odd number of digits).
• 2 contains 1 digit (odd number of digits).
• 6 contains 1 digit (odd number of digits).
• 7896 contains 4 digits (even number of digits).
• Therefore only 12 and 7896 contain an even number of digits.
91. Given an array of integers, check if there exists two integers N and M such that N is the double of
M ( i.e. N = 2 * M). More formally check if there exists two indices i and j such that :
o i != j
o 0 <= i, j < arr.length
o arr[i] == 2 * arr[j]
A. Example 1:
i. Input: arr = [10, 2, 5, 3]
ii. Output: true
• Explanation: N = 10 is the double of M = 5,that is, 10 = 2 * 5.
92. Given the array nums, for each nums[i] find out how many numbers in the array are smaller than
it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j]
< nums[i]. Return the answer in an array.
A. Example 1:
i. Input: nums = [8, 1, 2, 2, 3]
ii. Output: [4, 0, 1, 1, 3]
• Explanation:
• For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3).
• For nums[1]=1 does not exist any smaller number than it.
• For nums[2]=2 there exist one smaller number than it (1).
• For nums[3]=2 there exist one smaller number than it (1).
• For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).
Functions
93. Write a function to find the square of any number.
A. Example :
i. Input any number for square : 20
ii. Expected Output : The square of 20 is : 400.00
94. Write functions for the following operations.
• insert(val): Inserts an item val to the set if not already present.
• remove(val): Removes an item val from the set if present.
• getRandom: Returns a random element from current set of elements.
95. Write a function to swap two numbers.
A. Example :
i. Input 1st number : 2
ii. Input 2nd number : 4
iii. Expected Output :
• Before swapping: n1 = 2, n2 = 4
• After swapping: n1 = 4, n2 = 2
96. Write a function to check a given number is even or odd.
A. Example :
i. Input any number : 5
ii. Expected Output : The entered number is odd.
97. Write a function to find the sum of the series 1!/1+2!/2+3!/3+4!/4+5!/5+ ... +N!/N.
A. Example:
i. Input: 5
ii. Expected Output : The sum of the series is : 34
• Explanation: sum of 1!/1+2!/2+3!/3+4!/4+5!/5
98. Write a function to check whether a number is a prime number or not.
A. Example :
i. Input a positive number : 5
ii. Expected Output : The number 5 is a prime number.
99. Write a function to check Armstrong and perfect numbers.
A. Example :
i. Input any number: 371
ii. Expected Output :
iii. The 371 is an Armstrong number.
iv. The 371 is not a Perfect number.
100. Write a function to print all perfect numbers in given range.
A. Example :
i. Input lowest search limit of perfect numbers : 1
ii. Input lowest search limit of perfect numbers : 100
iii. Expected Output : The perfect numbers between 1 to 100 are : 6 28
101. Write a function that takes an integer number as a parameter and returns the resultant binary
number.
A. Example
i. Input
• Please enter number: 9
ii. Output
• Binary equivalent of 9 is: 1001

Advanced Problems
1. Sudoku: Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to
fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 sub-grids that
compose the grid (also called "boxes", "blocks", or "regions") contain all of the digits from 1 to 9.
[source: Wiki]
A. Part 1: Write a function for a sudoku puzzle setter that generates random legitimate
(solvable) sudoku puzzles and saves the puzzle in a file.
B. Part 2: Write a function for a sudoku puzzle solver that takes a sudoku puzzle file and
prints out the solved puzzle.
2. File System: Write a program which simulates a file system for text files.
Your program should be able to:
A. Add new text files and remove existing files in the system
B. Display list of files in your system and other metadata as needed, such as
i. Name of the file
ii. Size of the file
iii. Initial add date
iv. Last open date
v. And other information etc.
C. Display contents of existing files
Your program would maintain a single database-esque file that contains data for all the files as
well as a data structure (stored in the same database file) which maintains records of the starting
and end location of each file and other metadata as needed.

You might also like