Skip to content

deverl/frequent_numbers

Repository files navigation

Most Frequent Numbers

Overview

The programs in this project are possible solutions to a problem where you are given an integer array nums and integer k and you are to return the k most frequent elements from nums.

The results may be returned in any order.

See problem.txt for some sample data and the expected results.

Notes

  1. There are probably many ways this problem could be solved. These are just some examples.

Running

There is a makefile that can run each of the programs, building executables if required (go, c, cpp, java).

You can run any of the programs with make RUNTARGET where RUNTARGET is one of:

  • runc
  • runcpp
  • rungo
  • runjava
  • runlua
  • runpython (or runpy)
  • runjavascript (or runjs)
  • runphp

Cleanup

There is also a make target to clean up all of the executables and intermediate files. Use make clean to cleanup.

Caveats

None of these solutions take special care to handle these situations:

  • Where there are multiple input elements with the same frequency. There is no guarantee on the output in this case.
  • Where there are fewer values in nums than requested by the value of k

About

Solutions to the k most frequent numbers problem

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published