Oracle
Cognizant Interview Questions and Answers
Q1. Modified Balanced Parentheses where a character can be matched with any other character, i.e. / with &, ! with ? and so on.
Modified Balanced Parentheses where characters can be matched with any other character.
Use a stack to keep track of opening characters
When encountering a closing character, check if it matches the top of the stack
If it matches, pop from the stack, else return false
Continue until end of string, return true if stack is empty
Q2. Given an array of strings, print all the possible combinations of strings created by picking one character from each string of the array. The individual strings do not contain any duplicates. Ex: {ABC, DE} Ans...
read morePrint all possible combinations of strings by picking one character from each string in the array.
Iterate through each character of the first string and combine it with each character of the second string.
Repeat the process for all strings in the array to get all possible combinations.
Use nested loops to generate combinations efficiently.
Q3. Given a date in string format, write a java program to return the date n days after the given date. Solve the question without using DateTimeFormatter or any similar Date parsing libraries.
Java program to calculate date n days after given date without using Date parsing libraries.
Parse the input date string to extract day, month, and year components.
Calculate the total number of days represented by the input date.
Add the specified number of days to the total days calculated.
Convert the final total days back to day, month, and year components to get the new date.
Q4. Print all combinations of numbers in an array which sum up to a number k. Ex : Arr={3,1,4,5} k=5 Ans : {{1,4},{5}}
Use backtracking to find all combinations of numbers in an array that sum up to a given number.
Start by sorting the array in non-decreasing order to easily identify combinations.
Use backtracking to recursively find all combinations that sum up to the target number.
Keep track of the current combination and the remaining sum as you traverse the array.
Add the current combination to the result when the sum equals the target number.
Q5. Print all Pythagorean triplets within a given range.
Print Pythagorean triplets within a given range.
Iterate through all possible combinations of a, b, and c within the given range
Check if a^2 + b^2 = c^2 for each combination
Print the triplets that satisfy the Pythagorean theorem
Q6. Check if given string has Balanced Parentheses.
Check if a string has balanced parentheses.
Use a stack to keep track of opening parentheses.
Iterate through the string and push opening parentheses onto the stack.
When a closing parenthesis is encountered, pop from the stack and check if it matches the closing parenthesis.
If stack is empty at the end and all parentheses are matched, the string has balanced parentheses.
More about working at Oracle
Top HR Questions asked in Cognizant
Interview Process at Cognizant
Top Applications Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month