Programs for Interview: Coding Questions with Solutions in Python, Java, C and JavaScript
By the Techsnap careers team · Updated · 4 min read
Fresher technical interviews almost always include a few short programs: reversing a string, checking a palindrome or prime, finding duplicates, sorting an array. They are simple, which is why interviewers expect them to be correct, clean and well explained.
Pick your interview language below. Each guide has working code, output, an explanation of the approach and complexity, and the concept questions that usually follow.
What programs are asked in coding interviews for freshers?
Freshers are most often asked to reverse a string or number, check palindromes, prime and Armstrong numbers, print Fibonacci series and factorials, count characters, find duplicates or the second largest element in an array, check anagrams, sort an array and solve two sum.
Programs for interview by language
- Python programs for interview12 programs with solutions and Python concept questions
- Java programs for interview10 programs with solutions and Java concept questions
- C programs for interview10 programs with solutions and C concept questions
- JavaScript programs for interview10 programs with solutions and JavaScript concept questions
The topics these programs cover
| Topic | Typical programs | Concept tested |
|---|---|---|
| Strings | Reverse, palindrome, anagram, character count | Immutability, hashing |
| Numbers | Prime, Armstrong, factorial, Fibonacci, reverse a number | Loops, recursion, overflow |
| Arrays | Duplicates, second largest, two sum, sorting | Hash maps, single-pass logic |
| Recursion | Factorial, flatten nested lists | Base cases, stack usage |
| Language features | Pointers in C, closures in JavaScript, collections in Java | How the language works |
Once you are comfortable with these, move on to timed problems in the coding interview question bank and practise explaining your code in a live coding interview.
Run these programs yourself
Open a free in-browser compiler, type the programs from memory and test your own edge cases.
Frequently asked questions
Which language is best for coding interviews?
The one you know best. Python is quickest to write, Java and C++ are common in Indian IT interviews, and JavaScript suits frontend roles. Most companies let you choose.
How many programs should I practise before a placement interview?
Make sure you can write the 10 to 12 standard programs in your language from memory and explain them, then practise 50 or more varied problems to build pattern recognition.
Related interview guides
- Interview preparation guideThe complete plan for freshers and experienced
- 25 interview tipsBefore, during and after the interview
- Interview questions and answers22 common questions with sample answers
- Interview dress codeWhat to wear for men, women and online
- Live coding interview guideWhiteboard, shared editor and pair programming
- AI mock interviewsPractise out loud with instant feedback