Choosing a language for interviews

Open on YouTube at 13:56

1 Pick one and stay with it

An interview gives us under an hour, often for two problems. Every minute spent remembering how to sort a list is a minute taken from the problem.

Many beginners switch languages every few weeks. After a year they know three languages a little and none of them well. The goal is the opposite: one language we know so well that we stop noticing it.

Most companies let us pick any common language. The interviewer judges the method and how we explain it, not the language. So which language we pick matters less than sticking with it.

2 What actually matters

Four things make a language easier or harder in an interview:

  • The library. Does it come with sorting, a map, a set and a heap ready to use? DSA problems need all four.
  • Length. How much do we type for one idea? More lines means more chances for a typo.
  • Traps. Where does the language quietly do something unexpected?
  • Speed. How fast does the code run?

Speed matters least. With the right method, all seven languages on oneby7 are fast enough.

3 One task in seven languages

Here is the same task in every language: return the value that appears most often in nums. For [7, 2, 2, 5, 7, 2] the answer is 2. We count each value in a map and remember the value with the highest count so far.

The method is the same in all seven. Only one line really changes: adding one to a count that may not exist yet.

LanguageAdd one to a count
C++, Gocounts[num]++ (a missing key starts at 0)
Javacounts.getOrDefault(num, 0) + 1
Pythoncounts.get(num, 0) + 1
JavaScript(counts.get(num) ?? 0) + 1
Rust*counts.entry(num).or_insert(0) += 1
C#counts.GetValueOrDefault(num, 0) + 1

In an interview we want to type that line without stopping to think. That only happens in a language we use every day.

4 What each language gives us

All seven can sort and have a map. The gaps are in sets and heaps:

LanguageSortMapSetHeap
C++sortunordered_mapunordered_setpriority_queue
JavaArrays.sortHashMapHashSetPriorityQueue
Pythonsorteddictsetheapq
JavaScript.sort((a, b) => a - b)MapSetNone
Goslices.SortmapNonecontainer/heap
Rust.sort()HashMapHashSetBinaryHeap
C#Array.SortDictionaryHashSetPriorityQueue

The lesson on the standard library goes through these one at a time.

5 One trap in each language

We only need to know the traps of the language we pick.

  • C++: overflow. An int holds up to about 2 × 10⁹, so adding two large values can give a wrong answer. Use long long when values can get that big.
  • Java: == on numbers from a map. A map stores Integer objects, and == compares objects, not values. It works for small numbers and fails for larger ones. Use .equals().
  • Python: speed. A plain loop runs about ten times slower than in C++. With the right method this rarely matters. Built-in calls like sorted are fast.
  • JavaScript: big numbers and sorting. Whole numbers stay exact only up to about 9 × 10¹⁵. And sort() compares as text, so [10, 9, 1].sort() gives [1, 10, 9]. Always pass (a, b) => a - b.
  • Go: no set, and a heap takes setup. Use map[int]bool as a set. A heap needs a small type with five methods, written once and then reused.
  • Rust: strict ownership rules. They catch real bugs but make trees and graphs slow to write at first. Indexes are usize, so i - 1 at i = 0 crashes.
  • C#: overflow. As in C++, an int holds up to about 2 × 10⁹. A bigger result silently wraps to a wrong number. Use long.

The next lesson, on input, output and data types, explains overflow in full.

6 Which one to pick

  • Already know one of the seven well? Use it. Habit beats any feature another language offers.
  • Know none? Pick C++, Java or Python. All three have every tool above and are the most common in interviews. Python is the easiest start. C++ is the fastest. Java fits if your college or target company uses it.
  • Choosing between them to learn DSA well? C++ or Java teaches more than Python. Python does a lot for us: its numbers never overflow, and one call like Counter or a slice does work we would otherwise write ourselves. That saves time, but it hides how the work is done. In C++ or Java we handle more of it ourselves, and we understand the data structures and algorithms better for it.
  • Use JavaScript, Go, Rust or C# at work? They are fine too. Just learn their gaps from the two tables above.

Switching later is easy, because the methods in this course work the same in every language. Only the spelling changes, as the seven tabs above show.

The habit to keep: solve every problem in this course in one language. Keep a short page of its calls for sorting, maps, sets and heaps until you no longer need to look them up.

Finished this lesson?

Mark it read and it is ticked on the roadmap and in the list.

Article

Send feedback

Thank you for helping. We read every report and fix what is wrong.

How do you feel about oneby7?

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.