TCS wings1 DCA python coding
TCS elevate wings1 coding questions
This post contains only coding questions asked in TCS digital wings1 or tcs elevate wings1 exam.
If anyone want coding answer of these questions please comment me or reach me through email provided.
Given a string str which consists of only 3 letters representing the color,(H) Hue, (S) Saturation, (L) Lightness, called HSL colors. The task is to count the occurrence of ordered triplet “H, S, L” in a given string and give this count as the output.
This question was asked in April 21 Digital Capababilty Assessment
Examples:
A) Input
HHSL
Output
2
Explanation: There are two triplets of RGB in the given string:
H at index O, S at index 2 and Lat index 3 forms one triplet of HSL.
H at index 1, S at index 2 and Lat index 3 forms the second triplet of HSL.
B) Input:
SHL
Output: 0
Explanation: No triplets exists.
In this 3 Palindrome, Given an input string word, split the string into exactly 3 palindromic substrings. Working from left to right, choose the smallest split for the first substring that still allows the remaining word to be split into 2 palindromes.
Similarly, choose the smallest second palindromic substring that leaves a third palindromic substring.
If there is no way to split the word into exactly three palindromic substrings, print “Impossible” (without quotes). Every character of the string needs to be consumed.
Cases not allowed –
After finding 3 palindromes using above instructions, if any character of the original string remains unconsumed.
No character may be shared in forming 3 palindromes.
Constraints
1 <= the length of input sting <= 1000
Input
First line contains the input string consisting of characters between [a-z].
Output
Print 3 substrings one on each line.
Time Limit
1
Example 1
Input
nayannamantenet
Output
nayan
naman
tenet
Explanation
The original string can be split into 3 palindromes as mentioned in the output.
However, if the input was nayanamantenet, then the answer would be “Impossible”.
Example 2
Input
aaaaa
Output
a
a
aaa
Explanation
The other ways to split the given string into 3 palindromes are as follows –
[a, aaa, a], [aaa, a, a], [aa, aa, a], etc.
Since we want to minimize the length of the first palindromic substring using left to right processing, the correct way to split is [a, a, aaa].
You are given an array prices where prices[i] is the price of a given stock on the ith day.
You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0
Example 1:
Input: prices = [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must bu y before you sell.
Input: prices = [7,6,4,3,1]
Output: 0
Explanation: In this case, no transactions are done and the max profit = 0.
A physical education teacher asks the students to assemble in a straight line for morning assembly. Inspite of repeated instructions, the student do not obey the teacher. Given an array (a[]) of N numbers of elements in which each element represent the heigh of the student in that position. The task here is to find the no. Of students, only for Dislike students numbered 1 to N-1(a[1] to a[N-1]) whose height is less than the height of their adjacent student.
Constraints: 0<N<=50
Input format for testing: The candidate must write the code to accept two First input: Accept value of N ( positive integer Number)
Second Input : Accept N numbers of positive integer values (a[]) where each value is separated by a new line. 04
Output format: the output should be a positive
integer number additional messages in output will cause the Dislike failure of testcases
Input:
5
35 15 45 25 55
Output:
2
Explanation
From the input array given above
64
a[0]=35
a[1]=15
a[2]=45
a[3]=25
a[4]=55
The elements whose adjacent values are greater are 15, 25
Example 2
Input:
7
1,15,13,12,10,1,0
Output:
0
From the input array given above none of the elements are smaller as compared to their adjacent elementsike Hence the output is 0.
In this even odd problem Given a range [low, high] (both inclusive), select K numbers from the range (a number can be chosen multiple times) such that sum of those K numbers is even.
Calculate the number of all such permutations.
As this number can be large, print it modulo (1e9 +7).
Constraints
0 <= low <= high <= 10^9
K <= 10^6.
Input
First line contains two space separated integers denoting low and high respectively
Second line contains a single integer K.
Output
Print a single integer denoting the number of all such permutations
Example 1
Input
4 5
3
Output
4
Explanation
There are 4 valid permutations viz. {4, 4, 4}, {4, 5, 5}, {5, 4, 5} and {5, 5, 4} which sum up to an even number.
Example 2
Input
1 10
2
Output
50
Explanation
There are 50 valid permutations viz. {1,1}, {1, 3},.. {1, 9} {2,2}, {2, 4},… {2, 10} . . . {10, 2}, {10, 4},… {10, 10}. These 50 permutations, each sum up to an even number.
Comments