Posts

Featured post

BACKWARD AND FORWARD STRING

Image
BACKWARD AND FORWARD STRING PROBLEM STATEMENT : Consider one string as input. You have to check whether the strings obtained from the input string with single backward and single forward shifts are the same or not. If they are the same, then print 1, otherwise, print 0. Hint: Backward shift: A single circular rotation of the string in which the first character becomes the last character and all the other characters are shifted one index to the left. For example, “abcde” becomes “bcdea” after one backward shift. Forward shift: A single circular rotation of the string in which the last character becomes the first character and all the other characters are shifted to the right. For example, “abcde” becomes “eabcd” after one forward shift. Constraints: String str should not allow space, special characters, and numbers. String str should only be in the English language. 1 <= len(str) <=1000 Example Input/Output 1: Input: ( ) sfdlmnop Output: 0 Explanation:  In the firs...

Split Balanced Parentheses

Image
 Split Balanced Parentheses PROBLEM STATEMENT : The program must accept a string S as the input. The string S contains only parentheses, where each open parenthesis '(' has a matching close parenthesis ')' . The program must split the string S into as many substrings as possible, where the parentheses in each substring must be balanced. Boundary Condition(s): 2 <= Length of S <= 100 Input Format: The first line contains S. Output Format: The lines contain the substrings of S based on the given conditions. Example Input/Output 1: Input: ( ) ()() Output: () () Explanation:  There are two balanced substrings in S. Hence the output is () () Example Input/Output 2: Input: ( ) ()((())())((()))(()(())()) Output: () ((())()) ((())) (()(())()) Example Input/Output 3: Input: ( ) (()(()()))()(((()))()(()))(()((()))(())())(())() Output: (()(()())) () (((()))()(())) (()((()))(())()) (()) ()                 ...

Integers - Divide and Add Remainders

Image
 Integers - Divide and Add Remainders PROBLEM STATEMENT : The program must accept N integers and an integer K. Starting from the 1st element to the Kth element, the program must divide the integers starting from the K+1th element and add the respective remainders to the array elements. The program must finally print the revised array values. Boundary Condition(s): 1 <= K < N <= 100 1 <= Each integer value <= 10^5 Input Format: The first line contains N. The second line contains N integer values separated by a space. The third line contains K. Output Format: The first line contains the revised array values separated by a space. Example Input/Output 1: Input: ( ) 5 10 24 61 78 90 2 Output: 10 24 76 100 108 Explanation:  Here K=2. After dividing by 10 and adding the remainders the array becomes 10 24 62 86 90. After dividing by 24 and adding the remainders the array becomes 10 24 76 100 108. Example Input/Output 2: Input: ( ) 6 12 49 86 57 18 6...

Knight - Possible Moves

Image
 Knight - Possible Moves PROBLEM STATEMENT : The program must accept the position of a Knight (Horse) in a chessboard denoted by the letter 'H'  and print the number of moves M it can make from that position. Assume no other pieces are on the chessboard which is denoted by the letter B . Note: In Chess, a knight can move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). Input Format: 8 lines and one line among them containing the letter H. Output Format: The first line contains M. Example Input/Output 1: Input: ( ) B B B B B B H B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B Output: 3 Explanation:  The positions where the Knight can move are indicated by ' * '. B B B B B B H B B B B B * B B B B B B B B * B * B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B As three moves are possib...

Functions in C Problem 1

Image
 Functions in C Problem 1 PROBLEM STATEMENT : The function/method getProductSign accepts two arguments - SIZE and arr . The integer SIZE represents the size of the integer array arr.  The function/method getProductSign must return the sign of the product of all the integers in the given array.  - If the product is a positive value, then the function must return 1 .  - If the product is a negative value, then the function must return -1 .  - If the product is 0 , then the function must return 0.  Your task is to implement the function getProductSign so that the program runs successfully. Boundary Condition(s):  1 <= N <= 1000  -100 <= Each integer value <= 100  Example Input/Output 1: Input: 4 -1 2 3 -4 Output: 1 Explanation: The product of the given four integers is 24 (-1 * 2 * 3 * -4). Here 24 is a positive value, so 1 is printed. Example Input/Output 2: Input: 5 10 20 -30 4 5 Output: -1 Example Input/Output 3: Input: 3 -6 0 -5 ...

Sort Integers - Outside Square Brackets

Image
 Sort Integers - Outside Square Brackets PROBLEM STATEMENT : The program must accept a list of integers where some groups of integers are enclosed within a pair of square brackets. The program must sort(in-place) the integers that occur outside the square brackets in the given list. Then the program must print the revised list of integers as the output. Note: The given list does not have nested square brackets. Boundary Condition(s): 1 <= Number of integers in the given list <= 100 1 <= Each integer value <= 10^5 Input Format: The first line contains a list of integers separated by a space, where some groups of integers are enclosed within a pair of square brackets. Output Format: The first line contains the revised list of integers based on the given conditions. Example Input/Output 1: Input: ( ) 40 20 [50 10 60] 30 [9 8 7 5 1] 15 65 25 Output: 15 20 [50 10 60] 25 [9 8 7 5 1] 30 40 65 Explanation:  The integers that occur outside the square brackets ar...

Laptops & WI-FI Hotspots

Image
Laptops & WI-FI Hotspots PROBLEM STATEMENT : The program must accept a string S as the input. The string S contains only the asterisks(*), the hash symbols(#), the hyphens(-), and the alphabet(L). - Each asterisk represents a WI-FI hotspot. - Each hash symbol represents an obstacle. - Each hyphen represents empty space. - Each alphabet L represents a laptop. Each laptop has a special feature of connecting to any Wi-Fi network from any distance away, as long as there are not any obstructions between the hotspot and the laptop. For each laptop, the program must print the number of WI-FI hotspots that the laptop can connect as the output. Note: The alphabet L always occurs at least once in the string. Boundary Condition(s): 1 <= Length of S <= 100 Input Format: The first line contains S. Output Format: The first line contains the integer values representing the number of WI-FI hotspots that the laptop can connect. Example Input/Output 1: Input: ( ) *---L--*---* Output: ...