0% found this document useful (0 votes)
7 views3 pages

Coding_Practice_Problems_CSE

The document presents a series of coding practice problems commonly encountered in CSE interviews, along with their Python solutions. It includes problems such as reversing a string, checking for prime numbers, generating Fibonacci series, calculating factorial using recursion, finding a missing number in an array, checking for palindromes, and printing patterns. Each problem is accompanied by a concise Python function that provides a solution.
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)
7 views3 pages

Coding_Practice_Problems_CSE

The document presents a series of coding practice problems commonly encountered in CSE interviews, along with their Python solutions. It includes problems such as reversing a string, checking for prime numbers, generating Fibonacci series, calculating factorial using recursion, finding a missing number in an array, checking for palindromes, and printing patterns. Each problem is accompanied by a concise Python function that provides a solution.
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/ 3

Coding Practice Problems with Solutions - CSE Interviews

1. Reverse a String

-------------------

Q: Write a program to reverse a string.

Python Solution:

def reverse_string(s):

return s[::-1]

2. Check Prime Number

---------------------

Q: Write a program to check if a number is prime.

Python Solution:

def is_prime(n):

if n <= 1:

return False

for i in range(2, int(n**0.5) + 1):

if n % i == 0:

return False

return True

3. Fibonacci Series

-------------------

Q: Print first n Fibonacci numbers.

Python Solution:

def fibonacci(n):
a, b = 0, 1

for _ in range(n):

print(a, end=' ')

a, b = b, a + b

4. Factorial using Recursion

----------------------------

Q: Find factorial of a number using recursion.

Python Solution:

def factorial(n):

if n == 0:

return 1

else:

return n * factorial(n - 1)

5. Missing Number in Array (1 to n)

-----------------------------------

Q: Find the missing number in an array of size n-1 with numbers 1 to n.

Python Solution:

def find_missing(arr, n):

total = n * (n + 1) // 2

return total - sum(arr)

6. Palindrome Check

-------------------

Q: Check if a string is a palindrome.

Python Solution:
def is_palindrome(s):

return s == s[::-1]

7. Pattern Printing

-------------------

Q: Print a right-angle triangle pattern of stars.

Python Solution:

def print_pattern(n):

for i in range(1, n+1):

print('*' * i)

You might also like