[Go to site: main page, start]

0% found this document useful (0 votes)
4 views5 pages

MNC Programming Questions Java Python

This document provides a list of 20 important programming questions commonly asked in MNC coding interviews for Java and Python developers, along with sample solutions for each question. Topics covered include factorial calculation, palindrome checking, Fibonacci series, and more. Additionally, it offers preparation tips such as practicing coding daily and understanding time complexity.

Uploaded by

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

MNC Programming Questions Java Python

This document provides a list of 20 important programming questions commonly asked in MNC coding interviews for Java and Python developers, along with sample solutions for each question. Topics covered include factorial calculation, palindrome checking, Fibonacci series, and more. Additionally, it offers preparation tips such as practicing coding daily and understanding time complexity.

Uploaded by

jude12367
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

20 Important MNC Programming Questions with Answers

(Java & Python)


This document contains important programming questions frequently asked in MNC coding
interviews for Java and Python developers along with sample solutions.

1. Factorial of a Number

Java:
int fact = 1;
for(int i=1;i<=n;i++){
fact *= i;
}

Python:
fact = 1
for i in range(1,n+1):
fact *= i

2. Palindrome Number

Java:
int rev=0,temp=n;
while(temp>0){
rev = rev*10 + temp%10;
temp/=10;
}

Python:
rev = int(str(n)[::-1])

3. Fibonacci Series

Java:
int a=0,b=1,c;
for(int i=0;i<n;i++){
c=a+b;
a=b;
b=c;
}

Python:
a,b = 0,1
for i in range(n):
print(a)
a,b = b,a+b

4. Prime Number Check

Java:
boolean prime=true;
for(int i=2;i<=n/2;i++){
if(n%i==0) prime=false;
}

Python:
prime = all(n%i!=0 for i in range(2,n//2+1))

5. Reverse a String

Java:
String rev = new StringBuilder(str).reverse().toString();

Python:
rev = str[::-1]

6. Swap Two Numbers

Java:
int temp=a;
a=b;
b=temp;

Python:
a,b = b,a

7. Find Largest Element in Array

Java:
int max=arr[0];
for(int i:arr)
if(i>max) max=i;

Python:
max_num = max(arr)

8. Count Vowels in String

Java:
int count=0;
for(char c:[Link]()){
if("aeiouAEIOU".indexOf(c)!=-1) count++;
}

Python:
count = sum(1 for c in s if [Link]() in 'aeiou')

9. Sort an Array

Java:
[Link](arr);

Python:
[Link]()

10. Linear Search

Java:
for(int i=0;i<[Link];i++){
if(arr[i]==key) return i;
}

Python:
index = [Link](key)

11. Binary Search

Java:
[Link](arr,key);

Python:
import bisect
index = bisect.bisect_left(arr,key)

12. Armstrong Number

Java:
while(temp>0){
rem=temp%10;
sum += rem*rem*rem;
temp/=10;
}

Python:
sum(int(d)**3 for d in str(n))

13. Check Even or Odd

Java:
if(n%2==0)

Python:
if n%2==0:

14. Sum of Digits

Java:
while(n>0){
sum += n%10;
n/=10;
}

Python:
sum_digits = sum(int(d) for d in str(n))

15. Find Duplicate Elements

Java:
HashSet<Integer> set = new HashSet<>();

Python:
duplicates = set([x for x in arr if [Link](x)>1])

16. Remove Duplicates from List

Java:
Set<Integer> set = new LinkedHashSet<>(list);

Python:
list(set(arr))

17. Matrix Addition

Java:
c[i][j] = a[i][j] + b[i][j];

Python:
c = [[a[i][j]+b[i][j] for j in range(col)] for i in range(row)]

18. Count Words in String

Java:
String[] words = [Link](" ");

Python:
count = len([Link]())

19. Find Second Largest Number

Java:
[Link](arr);
second = arr[[Link]-2];

Python:
second = sorted(arr)[-2]

20. Anagram Check

Java:
char[] a=[Link]();
char[] b=[Link]();
[Link](a);
[Link](b);

Python:
sorted(str1)==sorted(str2)

Preparation Tips
• Practice coding daily on LeetCode, HackerRank, or CodeChef.

• Understand time complexity and optimization.

• Revise arrays, strings, recursion, and OOP concepts.

• Practice both Java and Python syntax.

• Prepare for debugging and output-based questions.

You might also like