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

Java

Coding Bites_101: Important Packages in Python for Data Science

[SOLVED] Error Another app is currently holding the yum lock

Your First Versioned API with Phoenix Framework

Containerizing My First Database App

Robust Reasons To Use Drupal For Enterprise-Level Website

Planning for Agile

MongoDB Atlas Serverless Testing

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

Leetcode — 1. Two Sum

How does bike rentals relate to insertion sort, online learning, and caching?

Implementation of Heap data structure :

How to print all unique subsets of a set, using recursion and bit-manipulation.