Ugly Number II - Dynamic Programming

Input: n = 10
Output: 12
Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.
  1. 1 is typically treated as an ugly number.
  2. n does not exceed 1690.
1*2, 2*2, 3*2, 4*2, ...
1*3, 2*3, 3*3, 4*3, ...
1*5, 2*5, 3*5, 4*5, ...
we take the elements in order of -
1*2, 1*3, 2*2, 1*5, 2*3, 3*3, 2*5, ...

--

--

--

I am Indian by birth, Punjabi by destiny. Humanity is my religion. Love to eat, travel, read books and my million dreams keep me alive.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

WHAT MAKES A GOOD DATA MODEL? — POINT 7:

14 Fantastic Learning Tools and Resources for Bash Scripting

READ/DOWNLOAD!%

Mutex with timeout or channels in go

Decorators — Python

Active Record: seeding data & the Faker gem

Flexible

Learn How to Manage the Disk Storage Prometheus Will Use

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Navneet Ojha

Navneet Ojha

I am Indian by birth, Punjabi by destiny. Humanity is my religion. Love to eat, travel, read books and my million dreams keep me alive.

More from Medium

Solutions for LeetCode 743

[Leetcode] K Closest Points to Origin

An Unconventional Approach to Determine Operator Precedence: Dijkstra’s Two-Stack Algorithm

Linked List | LeetCode Top Interview Questions