Skip to content

DSA Bonus Questions #24

Description

@asifmohammed1

Question 1: Find the Second Largest Element

Given an array of integers, find the second largest element.

Input

arr = [10, 20, 5, 8, 25]

Output

20

Example

Largest = 25
Second Largest = 20

Concepts

  • Arrays/Lists
  • Loops
  • Conditions

Question 2: Count Frequency of Elements

Given an array, count how many times each element appears.

Input

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

Output

{
    1: 2,
    2: 3,
    3: 1,
    4: 1
}

Concepts

  • Dictionary
  • Loops

Question 3: Check Palindrome Number

Given a number, check whether it is a palindrome.

Input

121

Output

Palindrome

Input

123

Output

Not Palindrome

Concepts

  • Loops
  • Modulus (%)
  • Integer Operations

Question 4: Find Missing Number

An array contains numbers from 1 to n with one number missing.

Find the missing number.

Input

arr = [1, 2, 3, 5]

Output

4

Hint

Expected numbers:

1 2 3 4 5

Actual numbers:

1 2 3 5

Missing:

4

Concepts

  • Arrays
  • Sum Formula
  • Loops

Interview Bonus

Reverse an Array

Input

[1, 2, 3, 4, 5]

Output

[5, 4, 3, 2, 1]

Find Maximum Element

Input

[10, 50, 20, 80, 30]

Output

80

Count Even and Odd Numbers

Input

[1, 2, 3, 4, 5, 6]

Output

Even = 3
Odd = 3

Sum of Digits

Input

1234

Output

10

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions