Timer is Running

Minimum Time
Submissions: 50   Accuracy:

20%

  Difficulty: Medium   Marks: 4

You are given time for insertion, deletion and copying, the task is to calculate the minimum time to write N characters on the screen using these operations. Each time you can insert a character, delete the last character and copy and paste all written characters i.e. after copy operation count of total written character will become twice.

Example 1:

Input: N = 9, I = 1, D = 2, C = 1  
Output: 5
Explanation: N characters can be written
on screen in 5 time units as shown below,
insert a character    
characters = 1,  total time = 1
again insert character      
characters = 2,  total time = 2
copy characters             
characters = 4,  total time = 3
copy characters             
characters = 8,  total time = 4
insert character           
characters = 9,  total time = 5
Example 2:
Input: N = 1, I = 10, D = 1, C = 5
Output: 10
Explanation: Insert one character


Your Task:  
You don't need to read input or print anything. Complete the function minTimeForWritingChars() which takes N, I, D and C as input parameters and returns the integer value

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Constraints:
1 ≤ N ≤ 106

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Govil
Author: Ayush Govil 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.