Accenture One Shot Coding
Accenture One Shot Coding
https://www.geeksforgeeks.org/basic-programming-problems/
Accenture One-Shot Coding Preparation
Accenture One-Shot Coding Preparation
Q1. Ann recently began using the metro to work. We are aware that a single ride on the metro costs one ruble. Ann
also learned that she can purchase a unique ticket for the rides (she can buy it several times). The price is b rubles.
Ann calculated that she would need to take the subway n times. Help Ann out by letting her know how much
money she must have in order to buy n rides.
Input
The four numbers n, m, a, b (1 n, m, a, b 1000) on a single line represent the number of rides Ann has scheduled,
the number of rides covered by the m ride ticket, the cost of a one ride ticket, and the cost of a m ride ticket.
Output
Print a single integer.
the minimum sum in rubles that Ann will need to spend.
Input 2:
Input 1: 5223
6212
Output:
9
Output:
6
Accenture One-Shot Coding Preparation
Q2. Floyd's Triangle Pattern
You have been given an integer N as input your task is to write a program to print N rows of Floyd's Triangle pattern. Floyd's
Triangle is a right-angled triangular array of natural numbers, used for the numbering of lines in a printout.
For N = 4
1
23
456
7 8 9 10
Accenture One-Shot Coding Preparation
Q3. Problem Statement: Sum of leaders of an Array
Implement the following function:
int SumOfLeaders (int arr[], int n);
The function accepts a positive integer array 'arr' of size 'n' as its argument. Implement the function to find the leaders in the
array and return their sum. An element is leader in the array if it greater than all the elements to its right side. The rightmost
element is always a leader.
Assumption: 'arr' contains distinct elements.
Note:
• If 'arr' is empty or None (in case of python), return -1
• Output lies within integer r
Input:
arr: 52 66 64 36 45 24 32
Output:
207
Explanation:
Leaders of array are {66, 64, 45, 32). Sum
= 66+64 +45 + 32 = 207. Thus, output is 207.
Accenture One-Shot Coding Preparation
Q4. Rohan is a kid who has just learned about creating words from alphabets. He has written some words in the notepad of
his father's laptop. Now his father wants to find the longest word written by Rohan using a computer program. Write a
program to find the longest string in a given list of strings.
Example:
Input: yes no number
Output: The longest string is: number
Accenture One-Shot Coding Preparation
Q5. Minimum Number of Integers
You are given a function,
int MinimumNumberOfIntegers (int* arr, int n, int x, int y);
The function accepts an integer array 'arr' of length 'n', an integer 'x' and an integer 'y' as its arguments. Implement the
function to count minimum number of integers present between 'x' and 'y' in the given array 'arr' and return the same.
Assumption:
• n> 1
• Values of 'x' and 'y' are distinct
• If 'x' or 'y' or both are not present in the given array 'arr', return -1
Example:
Input:
x: 3
y: 6
arr: 10 3 2 4 5 6 9 7 3
Output:
2
Explanation:
The count of minimum number of integers between '3' and '6' is 2 (i.e. 9 and 7).