TGViewer
Coding Projects Coding Projects @programming_experts · 67.9K subscribers
Post #2794 2.06K
🚀 Coding Interview Questions with Answers (Part 19)

1️⃣8️⃣1️⃣ How Do You Reverse a String?

Answer:

Reversing a string means arranging its characters in the opposite order.

Example:

Input: "hello"

Output: "olleh"

Python:

text = "hello"
reversed_text = text[::-1]
print(reversed_text)


Time Complexity: O(n)

Space Complexity: O(n)

1️⃣8️⃣2️⃣ How Do You Find the Largest Element in an Array?

Answer:

Traverse the array while keeping track of the largest value found so far.

Example:

Input: [10, 25, 7, 42, 18]

Output: 42

Python:

numbers = [10, 25, 7, 42, 18]

largest = numbers[0]

for num in numbers:
if num > largest:
largest = num

print(largest)


Time Complexity: O(n)

Space Complexity: O(1)

1️⃣8️⃣3️⃣ How Do You Find the Second Largest Element in an Array?

Answer:

Maintain two variables: one for the largest element and another for the second largest. Update them while traversing the array.

Example:

Input: [10, 25, 7, 42, 18]

Output: 25

Python:

numbers = [10, 25, 7, 42, 18]

largest = second = float('-inf')

for num in numbers:
if num > largest:
second = largest
largest = num
elif largest > num > second:
second = num

print(second)


Time Complexity: O(n)

Space Complexity: O(1)

1️⃣8️⃣4️⃣ How Do You Check Whether a String is a Palindrome?

Answer:

A palindrome is a string that reads the same forward and backward.

Examples:

"madam" → Palindrome

"level" → Palindrome

"hello" → Not a palindrome

Python:

text = "madam"

if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")


Time Complexity: O(n)

1️⃣8️⃣5️⃣ How Do You Find Duplicate Elements in an Array?

Answer:

Use a set to keep track of elements that have already appeared. If an element is already present in the set, it is a duplicate.

Example:

Input: [1, 2, 3, 2, 4, 1]

Output: [1, 2]

Python:

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

seen = set()
duplicates = set()

for num in numbers:
if num in seen:
duplicates.add(num)
else:
seen.add(num)

print(duplicates)


Average Time Complexity: O(n)

Space Complexity: O(n)

1️⃣8️⃣6️⃣ How Do You Remove Duplicates from an Array?

Answer:

A common approach is to use a set, which stores only unique values.

Example:

Input: [1, 2, 2, 3, 3, 4]

Output: [1, 2, 3, 4]

Python:

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

unique_numbers = list(set(numbers))

print(unique_numbers)


If the original order must be preserved:

unique_numbers = list(dict.fromkeys(numbers))


Average Time Complexity: O(n)

1️⃣8️⃣7️⃣ How Do You Find the Missing Number in an Array?

Answer:

If an array contains numbers from "1" to "n" with one number missing, calculate the expected sum and subtract the actual sum.

Example:

Input: [1, 2, 4, 5]

Output: 3

Python:

numbers = [1, 2, 4, 5]
n = 5

expected = n * (n + 1) // 2
missing = expected - sum(numbers)

print(missing)


Time Complexity: O(n)

Space Complexity: O(1)

1️⃣8️⃣8️⃣ How Do You Merge Two Sorted Arrays?

Answer:

Use two pointers to compare elements from both arrays and add the smaller element to the result.

Example:

Input:

[1, 3, 5]

[2, 4, 6]

Output:

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

Python:

a = [1, 3, 5]
b = [2, 4, 6]

i = j = 0
result = []

while i < len(a) and j < len(b):
if a[i] < b[j]:
result.append(a[i])
i += 1
else:
result.append(b[j])
j += 1

while i < len(a):
result.append(a[i])
i += 1

while j < len(b):
result.append(b[j])
j += 1

print(result)
  • ❤ 5
More from @programming_experts
  1. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  2. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
  3. Sep 29, 2026Post #2901
  4. Sep 29, 2026Post #2900
  5. Sep 29, 2026Post #2899
  6. Sep 29, 2026What will be the output? x = 10 if x > 5 and x < 10: print("Yes") else: print("No") A) Yes…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →