0% found this document useful (0 votes)
43 views6 pages

Company Specific Scenario Based Programs (6 Questions)

The document outlines multiple programming problems requiring implementations in various languages including C, C++, Java, and Python. Each problem specifies a function with input parameters and expected outputs, addressing tasks such as calculating food sufficiency for rats, evaluating binary operations, validating passwords, counting elements based on absolute differences, and summing numbers based on divisibility. The problems also include specific constraints and examples to illustrate the expected functionality.

Uploaded by

VINEETH KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views6 pages

Company Specific Scenario Based Programs (6 Questions)

The document outlines multiple programming problems requiring implementations in various languages including C, C++, Java, and Python. Each problem specifies a function with input parameters and expected outputs, addressing tasks such as calculating food sufficiency for rats, evaluating binary operations, validating passwords, counting elements based on absolute differences, and summing numbers based on divisibility. The problems also include specific constraints and examples to illustrate the expected functionality.

Uploaded by

VINEETH KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Write the program using any one of the programming language.

 C
 C++
 Java
 Python

01. Problem Description:


The function accepts two positive integers ‘r’ and ‘unit’ and a positive integer array
‘arr’ of size ‘n’ as its argument ‘r’ represents the number of rats present in an area,
‘unit’ is the amount of food each rat consumes and each ith element of array ‘arr’
represents the amount of food present in ‘i+1’ house number, where 0 <= i

Note:

 Return -1 if the array is null


 Return 0 if the total amount of food from all houses is not sufficient for all the rats.
 Computed values lie within the integer range.

Example:

Input:

 r: 7
 unit: 2
 n: 8
 arr: 2 8 3 5 7 4 1 2

Output:
4

Explanation:
Total amount of food required for all rats = r * unit

= 7 * 2 = 14.

The amount of food in 1st houses = 2+8+3+5 = 18. Since, amount of food in 1st 4
houses is sufficient for all the rats. Thus, output is 4.
02. Problem Description:

The Binary number system only uses two digits, 0 and 1 and number system can
be called binary string. You are required to implement the following function:

int OperationsBinaryString(char* str);

The function accepts a string str as its argument. The string str consists of binary digits
separated with an alphabet as follows:

 – A denotes AND operation


 – B denotes OR operation
 – C denotes XOR Operation

You are required to calculate the result of the string str, scanning the string to right
taking one operation at a time, and return the same.

Note:

 No order of priorities of operations is required


 Length of str is odd
 If str is NULL or None (in case of Python), return -1

Input:
str: 1C0C1C1A0B1
Output:
1

Explanation:
The alphabets in str when expanded becomes “1 XOR 0 XOR 1 XOR 1 AND 0 OR 1”, result of
the expression becomes 1, hence 1 is returned.
03. Problem description:
You are given a function.
int CheckPassword(char str[], int n);
The function accepts string str of size n as an argument. Implement the function
which returns 1 if given string str is valid password else 0.
str is a valid password if it satisfies the below conditions.

 – At least 4 characters
 – At least one numeric digit
 – At Least one Capital Letter
 – Must not have space or slash (/)
 – Starting character must not be a number

Assumption:
Input string will not be empty.

Example:

Input 1:
aA1_67
Input 2:
a987 abC012

Output 1:
1
Output 2:
0
04. Problem description:
You are given a function,
int findCount(int arr[], int length, int num, int diff);

The function accepts an integer array ‘arr’, its length and two integer variables
‘num’ and ‘diff’. Implement this function to find and return the number of
elements of ‘arr’ having an absolute difference of less than or equal to ‘diff’ with
‘num’.
Note: In case there is no element in ‘arr’ whose absolute difference with ‘num’ is
less than or equal to ‘diff’, return -1.

Example:
Input:

 arr: 12 3 14 56 77 13
 num: 13
 diff: 2

Output:
3

Explanation:
Elements of ‘arr’ having absolute difference of less than or equal to ‘diff’ i.e. 2 with ‘num’
i.e. 13 are 12, 13 and 14.
05. Problem description:
Implement the following Function

def differenceofSum(n. m)

The function accepts two integers n, m as arguments Find the sum of all numbers in
range from 1 to m(both inclusive) that are not divisible by n. Return difference between
sum of integers not divisible by n with sum of numbers divisible by n.

Assumption:

 n>0 and m>0


 Sum lies between integral range

Example

Input
n:4
m:20
Output
90

Explanation

 Sum of numbers divisible by 4 are 4 + 8 + 12 + 16 + 20 = 60


 Sum of numbers not divisible by 4 are 1 +2 + 3 + 5 + 6 + 7 + 9 + 10 + 11 + 13 +
14 + 15 + 17 + 18 + 19 = 150
 Difference 150 – 60 = 90

Sample Input
n:3
m:10
Sample Output
19
06. Problem description:

You are required to implement the following Function


def LargeSmallSum(arr)

The function accepts an integers arr of size ’length’ as its arguments you are
required to return the sum of second largest element from the even positions
and second smallest from the odd position of given ‘arr’

Assumption:

 All array elements are unique


 Treat the 0th position as even

NOTE

 Return 0 if array is empty


 Return 0, if array length is 3 or less than 3

Example
Input
arr:3 2 1 7 5 4

Output
7

Explanation

 Second largest among even position elements(1 3 5) is 3


 Second smallest among odd position element is 4
 Thus output is 3+4 = 7

Sample Input
arr:1 8 0 2 3 5 6
Sample Output
8

You might also like