Category Archives: Greedy

Convert Number n to 1 in Minimum Steps

Given a number n (n>=1 && n<=1018), your task is to convert it to 1 in minimum operation and constant space and time complexity. In one operation you can either – Subtract 1 from n if n>1. (or) Divide n by one of its proper divisor. Examples:- Input: n=2 Output: 1 2–>1. first move:- subtract 1 from n… Read More »