0% found this document useful (0 votes)
112 views9 pages

Cognizant Technical Round (3 Oct 2024)

Uploaded by

imrit33
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)
112 views9 pages

Cognizant Technical Round (3 Oct 2024)

Uploaded by

imrit33
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
You are on page 1/ 9

Cognizant Technical Round[3/10/2024]

Cluster 1: Java, SQL, HTML,CSS,JS

Q1) Write an SQL query to display: The loan id, load amount and loan disbursed date (loan date) of
all the loans taken from 1 June, 2023 and whose loan amount is between 50000 to 100000. Your
output should have 3 columns as given below:

SELECT loan_id, loan_amount, loan_date

FROM loans

WHERE loan_date >= '2023-06-01'

AND loan_amount BETWEEN 50000 AND 100000;

Q2)
SELECT ei.EMPNAME, si.TRAVELING_ALLOWANCE

FROM employee_info ei

JOIN dept_info di ON ei.DEPTID = di.DEPTID

JOIN salary_info si ON ei.EMPLOYEE_CATEGORY = si.EMPLOYEE_CATEGORY

WHERE di.LOCATION = 'BANGALORE'

AND ei.YRS_OF_EXP > 2;

Q3) Write java function for the following:

You are developing a weather analysis tool for a local meteorological department. Your tool is
designed to analyze temperature readings from various days to understand the variation in
temperatures over a specific period.

The department wants to quantify how much temperatures differ from one day to another. Your
task is to find and return an integer value representing the sum of the squares of the differences in
temperature readings for every unique pair of days in the given temperature array.

Input Specification:

input1 : An integer array representing the temperature reading of a particular day.

input2: An integer value representing the size of the array.


Output Specification: Return an integer value representing the sum of the squares of the differences
in temperature readings for every unique pair of days in the given temperature array.

Example 1:

input1: {1, 2, 3}

input2 : 3

Output: 6 Explanation: Here, the temperature on the specific day is {1, 2, 3} . The square of
differences in temperatures readings for every unique pair of days can be calculated as below:

• (1 - 2) ^ 2 = 1

• (1 - 3) ^ 2 = 4

• (2 - 3) ^ 2 = 1

The sum of the squares of differences is 1 + 4 + 1 = 6 Therefore, 6 is returned as the output.

Example 2:

input1: {4, 5}

input2: 2

Output: 1

Explanation: Here, the temperature on the specific day is {4, 5} The square of mragr differences in
temperatures readings for every unique pair of days can be calculated as below:

• (4 - 5) ^ 2 = 1 The sum of the squares of differences is 1. Therefore, 1 is returned as the output.

Code:

public class WeatherAnalysis {

public static int sumOfSquaresOfDifferences(int[] input1, int input2) {

int sum = 0;

// Iterate through every unique pair of temperatures

for (int i = 0; i < input2 - 1; i++) {

for (int j = i + 1; j < input2; j++) {

int difference = input1[i] - input1[j];

sum += difference * difference; // Square the difference and add to sum

}
return sum;

public static void main(String[] args) {

// Test Example 1

int[] input1 = {1, 2, 3};

int input2 = 3;

System.out.println(sumOfSquaresOfDifferences(input1, input2)); // Output: 6

// Test Example 2

int[] input1_2 = {4, 5};

int input2_2 = 2;

System.out.println(sumOfSquaresOfDifferences(input1_2, input2_2)); // Output: 1

Q4)

A poet has asked you for assistance in writing poems. He has given you a string S and a dictionary D
and he asks you to find, from the dictionary, a word which rhymes best with S. Words are said to
rhyme when the last syllables of the words are the same, like "cave" and "gave", or "typical" and
"critical." The words will be deemed to rhyme best if the last few characters of the words match the
most. Your task is to find and return a string value denoting the word which rhymes best with S,
from the dictionary D. If no such word is found, return the string "No Word".

Note: If all the characters match, it is the same word and not a rhyming word.

• All the given words are in lowercase. • If multiple rhyming words are found, then choose the word
with the least index.

Input Specification:

input1: A string value S, representing a single word

input2: A string array D, representing the dictionary

input3: An integer value representing the length of array D

Output Specification: Return a string value denoting the word which rhymes best with S from the
dictionary D. If no such word is found, return the string "No Word".

Example 1:

input1: thunder
input2: (puzzle, thunder, powder, blender, under)

input3: 5

Output: under

Explanation: Here, the given word S is "thunder." We can find the rhyming word/s trom the
dictionary in the followingway: • The first word "puzzle" does not rhyme at all and has no common
characters with the word "thunder" at the end. • The second word "thunder" is exactly the same
word as the given word, so it will not be considered as a rhyming word. • The third word is "powder"
and has the 3 letters "der" in common at the end and is the least rhyming among the list. • The
fourth word is "blender" and has the 4 letters "nder" in common at the end and is the second most
rhyming among the list. • The last word is "under" and it is the most rhyming word as it has the 5
letters "under" in common with the word at the end.
Since "under" is the most rhyming word among those in the given dictionary, under is returned as
the output.
Code:

public class RhymeFinder {

public static String findRhyme(String S, String[] D, int length) {

String bestRhyme = "";

int maxLength = 0;

for (String word : D) {

// Skip if the word is the same as S

if (word.equals(S)) {

continue;

int commonLength = 0;

int minLength = Math.min(S.length(), word.length());

// Check for common suffix length

for (int i = 1; i <= minLength; i++) {

if (S.charAt(S.length() - i) == word.charAt(word.length() - i)) {

commonLength++;

} else {

break;
}

// Update the best rhyme if this word has a longer common suffix

if (commonLength > maxLength) {

maxLength = commonLength;

bestRhyme = word;

return bestRhyme.isEmpty() ? "No Word" : bestRhyme;

public static void main(String[] args) {

String input1 = "thunder";

String[] input2 = {"puzzle", "thunder", "powder", "blender", "under"};

int input3 = 5;

String output = findRhyme(input1, input2, input3);

System.out.println(output); // Output: under

Q5)

You are creating a Password Reset Page for a new Website. The goal is to set up the correct style
and ids for Reset forms. However, the project is not yet complete, and you need to finish it.
Objectives:

• Create a button with type "submit", id "resetButton" and inner text "Reset Password".

• Change the color of the button's text to White

• If the passwords entered in the two input fields match, display the message "Password reset
successful", else display "Passwords do not match". The message should get displayed in the para
tag with the id "message".

Constraints: • Do not change the id or class attributes of any elements, as they are used by the
JavaScript code. • Ensure that the styling is applied correctly according to the provided CSS.
Here’s a simple example of how you can achieve the objectives for the password reset page using
HTML, CSS, and JavaScript:

HTML:

html

Copy code

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Password Reset</title>

<link rel="stylesheet" href="styles.css">

</head>

<body>

<div class="reset-container">

<h2>Reset Password</h2>

<form id="resetForm">

<label for="password">New Password:</label>

<input type="password" id="password1" required>

<label for="confirmPassword">Confirm Password:</label>

<input type="password" id="password2" required>

<button type="submit" id="resetButton">Reset Password</button>

</form>

<p id="message"></p>

</div>

<script src="script.js"></script>

</body>
</html>

CSS (styles.css):

/* Reset button styling */

#resetButton {

background-color: #007BFF; /* Bootstrap blue color */

color: white; /* Change the button text color to white */

padding: 10px 20px;

border: none;

border-radius: 5px;

cursor: pointer;

/* Additional form styling */

.reset-container {

max-width: 400px;

margin: 0 auto;

padding: 20px;

border: 1px solid #ccc;

border-radius: 10px;

background-color: #f9f9f9;

#message {

color: red;

font-size: 14px;

JavaScript (script.js):

// Handle new password submission with validation

document.getElementById('newPasswordForm').addEventListener('submit', function (event) {

event.preventDefault(); // Prevents the form from refreshing the page


var newPassword = document.getElementById('newPassword').value;

var confirmPassword = document.getElementById('confirmPassword').value;

var message = document.getElementById('message'); // Assuming there is a <p> or <span> with


id="message"

if (newPassword === confirmPassword) {

message.textContent = "Password reset successful";

message.style.color = "green"; // Success message color

} else {

message.textContent = "Passwords do not match";

message.style.color = "red"; // Error message color

});

Explanation:

● HTML: Creates a form with two password input fields and a button. A paragraph (<p>) with
the id="message" is used to display feedback to the user.

● CSS: Applies styling to the reset button and ensures the button's text color is white.

● JavaScript: Checks if the two passwords entered by the user match and updates the message
accordingly.

You might also like