Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Time complexity of finding a key by value in Javascript

I know that looking up a hash value by key is O(1) (constant time) but is it the same if you find the key that has a certain value? I'm looking up the key using:

const answer = Object.keys(dict).find(key => dict[key] === 1);

dict is an object that has integer keys.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That's O(n) time complexity, since you're performing a linear search on an array (the array returned by Object.keys). At worst, the item you want will be the last item in the array (or it won't be in the array at all), which would require n operations to determine (n being the length of the array) - hence, it's O(n) time.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!