Two (2) Keys Keyboard

Question Setup

Photo by Leone Venter on Unsplash

Analysis

  1. Copy ‘A’ and paste 3 times; or
  2. Minimum steps operations to get n = 2 i.e. ‘AA’ and copy then paste, i.e. f(4) = f(2) + 1 copy + 1 paste= 4.

Revelations — Prime Case of Oddity

Prime Numbers and Composite Numbers

TLDR

class Solution:
"""
@param n: The number of 'A'
@return: the minimum number of steps to get n 'A'
"""
def minSteps(self, n):
if n == 0 or n == 1:
return 0

primeTable = self.findPrimeNumbersToN(n)

res = 0
if primeTable[n] == False: #is not prime
#do prime factorisation
primeFactors = self.getListOfPrimeFactorsForComposite(n, primeTable)
for primeFactor in primeFactors:
res += primeFactor
else:
res = n #n is a prime number, return value of itself

return res

--

--

--

Writing to soothe the soul, programming to achieve flow

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

Recommended from Medium

Gaming the Christmas Market

Fill In Cell Mac Numbers App

Keeping it simple

How to create a login withGitHub and OAuth2

Content Encoding: why and how to use the meta charset tag and the Content-Type header

How to Secure a Spring Rest Service using Spring Aspect

How to Quickly Remember the 12 Agile Principles

Easy Hack 2 Apk Free Download

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
Mipsmonsta

Mipsmonsta

Writing to soothe the soul, programming to achieve flow

More from Medium

Algorithm Practice — getting greedy with Codeforces #790 question D) X_SUMS

Insert Data In Cosmos DB

Conditional/Branching Statements in Python

Getting Started with Git