Skip to main content

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

The topics these programs cover

TopicTypical programsConcept tested
StringsReverse, palindrome, anagram, character countImmutability, hashing
NumbersPrime, Armstrong, factorial, Fibonacci, reverse a numberLoops, recursion, overflow
ArraysDuplicates, second largest, two sum, sortingHash maps, single-pass logic
RecursionFactorial, flatten nested listsBase cases, stack usage
Language featuresPointers in C, closures in JavaScript, collections in JavaHow 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.