0% found this document useful (0 votes)
15 views3 pages

Coding Challenges and Solutions Guide

The document outlines various coding tasks and SQL queries from multiple companies including CapGemini, IBM, Ascendion, EPAM, Tiger Analytics, KPMG, TEZO, NTT Data, and ATAI Labs. Tasks include methods for summing numbers, manipulating dates, extracting data from tables, and implementing data structures. Each task specifies requirements for coding solutions in Python or SQL, focusing on algorithmic challenges and data handling.

Uploaded by

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

Coding Challenges and Solutions Guide

The document outlines various coding tasks and SQL queries from multiple companies including CapGemini, IBM, Ascendion, EPAM, Tiger Analytics, KPMG, TEZO, NTT Data, and ATAI Labs. Tasks include methods for summing numbers, manipulating dates, extracting data from tables, and implementing data structures. Each task specifies requirements for coding solutions in Python or SQL, focusing on algorithmic challenges and data handling.

Uploaded by

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

CapGemini:

Coding

- Write a method to return sum of two numbers, then implement the same within a class

- Given a date write a code to add two days and give the new date

- Write an SQl query to extract total marks from all active students. There are two tables:

Students: consisting of student ID and student name

Marks: Student name and marks1 , Marks 2

All the students in students table are active and for students names which are not there in marks
table, it should return 0

IBM Hacker Earth:

Python - Given startx and starty along with endx and endy and directions string like ewns which
indicates what step can be taken at a Given time, need to return least no of steps required to reach
endx and endy

SQL - extract id and name from customers in desc order of name if name is same order by asc order
of id

Ascendion:
8. Write a code for One Hot Encoding

9. Write a code for retrieving relevant chunks

EPAM:

Given a list of numbers in a sequence, Write a code to identify the missing number in a sequence

Tiger Analytics:

Coding:

Given a string Write a code to retrun the frequencies of each character

Given a list of numbers Write a code to return pairs of numbers which sum up to a given integer

KPMG:
Coding:

Given a matrix, write a code to output the elements in a spiral pattern anti clockwise
EPAM:
Coding:

Given a DF wth city, income, empname, etc, write a code to fetch the top n salaries of each city

TEZO:
Coding:

1. """

Write a program to remove duplicates from a sorted array in place.

- The input array is sorted in non-decreasing order.

- The output should contain only the unique elements from the array, and they should appear in the
same order as in the input.

- The operation must be done in place, meaning:

- You cannot use any extra data structures like lists, dictionaries, or sets to store intermediate results.

- You cannot use list operations like pop(), remove(), or any other function that alters the list
indirectly.

You must strictly rely on index manipulation within the same array to overwrite duplicates.

Input: {1, 1, 1, 2, 3, 3, 6, 6, 7}

Output: {1, 2, 3, 6, 7}

Explanation: The given input has only 1,2,3,6, and 7 as unique elements, hence the output only lists
them out.

"""

2. """

Given a string s containing three types of brackets {}, () and []. We have to determine whether the
brackets are balanced.

An expression is balanced if each opening bracket has a corresponding closing bracket of the same
type, the pairs are properly ordered and no bracket closes before its matching opening bracket.

Balanced:"[()()]{}" → every opening bracket is closed in the correct order.


Not balanced:"([{]})" → the ] closes before the matching { is closed, breaking the nesting rule.

Example:

Input: s = "[{()}]"

Output: true

Explanation: All the brackets are well-formed.

"""

KPMG:
Given a nxn matrix with random numbers, Write a code to print the same matrix but first with even
numbers in ascending order and then followed by odd numbers

NTT Data:
Coding:

Implement Queue data structure

ATAI Labs:

Coding:

Write a code to reverse a string without using any inbuilt methods (including slicing)

Write a code to print Fibonacci series

Common questions

Powered by AI

The SQL query should include an ORDER BY clause where the primary ordering is on the name column in descending order, followed by ID in ascending order for name duplicates. The query would be: SELECT id, name FROM Customers ORDER BY name DESC, id ASC. This ensures that names are ordered first in descending order and IDs follow ascending order only when names are identical.

Define initial two terms as variables, typically 0 and 1. Use a loop to iterate up to the desired number of terms. On each iteration, print the current term, then update the terms by setting the current term to the sum of the two previous terms, maintaining a rolling update. This avoids slicing and leverages simple addition and variable reassignment: prev, curr = 0, 1; for _ in range(n): print(prev); prev, curr = curr, prev + curr.

To implement this, you first write a function within a class that takes two parameters and returns their sum. For example, in Python: class Adder: def sum(self, a, b): return a + b. This method can then be called by creating an instance of the class and using the sum method, e.g., adder = Adder(); result = adder.sum(3, 4)

Iterate through the sorted array while maintaining an index for unique elements. Whenever a new unique element is found (not equal to the previous), it should be placed at the maintained index. Increment the index only for unique elements. This method ensures that the operation is performed in place and the array is overwritten correctly without using additional data structures: for 'arr = {1, 1, 2, 3}', the result is 'arr = {1, 2, 3}'.

One hot encoding involves converting categorical variables to binary vectors, representing presence (1) or absence (0) of each category level. Use libraries like Pandas in Python with get_dummies: df_encoded = pd.get_dummies(df, columns=['categorical_column']). This will replace the categorical column in the dataframe with binary columns for each category level. This process is crucial for algorithms that require numerical input.

Utilize a dictionary to store character counts. Iterate over the string, for each character increment its count in the dictionary. If the character is not in the dictionary, initialize it with a count of 1. At the end of iteration, the dictionary will contain all character frequencies. Example: def char_frequencies(s): freq = {}; for char in s: if char in freq: freq[char] += 1 else: freq[char] = 1 .

To display elements in an anti-clockwise spiral pattern, iterate over the matrix layers in a loop where each loop extracts the outer layer and prints it in anti-clockwise order: top row (left to right), right column (top to bottom), bottom row (right to left), and left column (bottom to top). Adjust matrix indices accordingly after each pass to exclude printed edges, and repeat until all elements are output. This requires managing boundaries and conditions dynamically for different matrix sizes.

You should define initial positions (startx, starty) and iterate over the directions string to update these positions. Map 'n', 's', 'e', 'w' to coordinate changes and count steps. If the current position matches (endx, endy), return the step count. Use conditionals to adjust coordinates: e.g., 'n' increments y, 's' decrements y, 'e' increments x, 'w' decrements x. Efficient code should handle edge cases where no path reaches target.

Use a stack to store opening brackets. Traverse the string, pushing each opening bracket onto the stack. For each closing bracket, check if the stack is empty or the stack's top doesn't match the closing type; if so, the string is unbalanced. If they match, pop the stack. After the traversal, if the stack is empty, the string is balanced. This method respects bracket hierarchy and sequence as required .

To achieve this, you should use a LEFT JOIN to include all students, even those without scores in the Marks table, and COALESCE to replace NULL values with 0. The query would be: SELECT s.student_id, s.student_name, COALESCE(SUM(m.marks1 + m.marks2), 0) AS total_marks FROM Students s LEFT JOIN Marks m ON s.student_name = m.student_name GROUP BY s.student_id, s.student_name.

You might also like