Amdocs
60+ Samavesh Marketing Interview Questions and Answers
Q1. Maximum Sum Increasing Subsequence of Length K Problem Statement
You are given an array NUMS
consisting of N integers and an integer K. Your task is to determine the maximum sum of an increasing subsequence of ...read more
Find the maximum sum of an increasing subsequence of length K in an array.
Iterate through the array and maintain a dynamic programming table to store the maximum sum of increasing subsequences of different lengths.
For each element, check all previous elements to find the increasing subsequences and update the maximum sum accordingly.
Return the maximum sum of the increasing subsequence of length K.
Example: For input [1, 2, 5, 4, 8] and K = 3, the maximum sum increasing subsequ...read more
Q2. First Unique Character in a String Problem Statement
Given a string STR
consisting of lowercase English letters, identify the first non-repeating character in the string and return it. If no such character exis...read more
Identify the first non-repeating character in a given string and return it, or '#' if none exists.
Iterate through the string to count the frequency of each character
Iterate through the string again to find the first character with frequency 1
Return the first non-repeating character or '#' if none exists
Q3. Implement Atoi Function
You have a string 'STR' of length 'N'. Your task is to implement the atoi function, which converts the string into an integer. If the string does not contain any numbers, the function sh...read more
Implement a function to convert a string to an integer, ignoring non-numeric characters and considering negative numbers.
Iterate through the characters of the string and check if they are numeric.
Handle negative numbers by checking the first character of the string.
Ignore non-numeric characters while converting the string to an integer.
Return 0 if there are no numbers in the string.
Ensure the resulting number is within the given constraints.
Q4. Subarray with Equal Occurrences Problem Statement
You are provided with an array/list ARR
of length N
containing only 0s and 1s. Your goal is to determine the number of non-empty subarrays where the number of 0...read more
Count the number of subarrays where the number of 0s is equal to the number of 1s in a given array of 0s and 1s.
Iterate through the array and keep track of the count of 0s and 1s encountered so far.
Use a hashmap to store the count of 0s and 1s encountered at each index.
For each index, check if the count of 0s and 1s encountered so far are equal. If yes, increment the total count of subarrays.
Q5. Pythagorean Triplets Detection
Determine if an array contains a Pythagorean triplet by checking whether there are three integers x, y, and z such that x2 + y2 = z2 within the array.
Input:
The first line contai...read more
Detect if an array contains a Pythagorean triplet by checking if x^2 + y^2 = z^2.
Iterate through all possible combinations of three numbers in the array.
Check if the sum of squares of any two numbers is equal to the square of the third number.
Return 'yes' if a Pythagorean triplet is found, otherwise return 'no'.
Q6. K - Sum Path In A Binary Tree
Given a binary tree where each node contains an integer value, and a value 'K', your task is to find all the paths in the binary tree such that the sum of the node values in each p...read more
Find all paths in a binary tree where the sum of node values equals a given value 'K'.
Traverse the binary tree using depth-first search (DFS) and keep track of the current path and its sum.
When reaching a leaf node, check if the sum equals 'K' and add the path to the result.
Continue DFS traversal for both left and right children, passing updated path and sum.
Return the list of paths that sum up to 'K'.
Q7. Fibonacci Number Verification
Identify if the provided integer 'N' is a Fibonacci number.
A number is termed as a Fibonacci number if it appears in the Fibonacci sequence, where each number is the sum of the tw...read more
The task is to determine if a given integer is a Fibonacci number or not.
Iterate through the Fibonacci sequence until the current number exceeds the given integer 'N'.
Check if the given integer 'N' matches any number in the Fibonacci sequence.
If a match is found, output 'YES'; otherwise, output 'NO'.
Q8. Reverse Stack with Recursion
Reverse a given stack of integers using recursion. You must accomplish this without utilizing extra space beyond the internal stack space used by recursion. Additionally, you must r...read more
Reverse a given stack of integers using recursion without using extra space or loop constructs.
Use recursion to pop all elements from the original stack and store them in function call stack.
Once the stack is empty, push the elements back in reverse order using recursion.
Base case of recursion should be when the original stack is empty.
Q9. Priority Queue Implementation
Ninja is tasked with implementing a priority queue using the Heap data structure. Since Ninja is busy with tournament preparations, your help is requested to complete this task.
Pr...read more
Implement a priority queue using Heap data structure with functions like push, pop, getMaxElement, and isEmpty.
Implement push() function to insert element into the priority queue.
Implement pop() function to delete the largest element from the queue.
Implement getMaxElement() function to return the largest element.
Implement isEmpty() function to check if the queue is empty.
Q10. Palindrome String Validation
Determine if a given string 'S' is a palindrome, considering only alphanumeric characters and ignoring spaces and symbols.
Note:
The string 'S' should be evaluated in a case-insensi...read more
Check if a given string is a palindrome after removing special characters, spaces, and converting to lowercase.
Remove special characters and spaces from the input string
Convert the string to lowercase
Check if the modified string is a palindrome by comparing characters from start and end
Q11. Nth Fibonacci Number Problem Statement
Calculate the Nth term in the Fibonacci sequence, where the sequence is defined as follows: F(n) = F(n-1) + F(n-2)
, with initial conditions F(1) = F(2) = 1
.
Input:
The inp...read more
Calculate the Nth Fibonacci number efficiently using dynamic programming.
Use dynamic programming to store previously calculated Fibonacci numbers to avoid redundant calculations.
Start with base cases F(1) and F(2) as 1, then iterate to calculate subsequent Fibonacci numbers.
Time complexity can be optimized to O(N) using dynamic programming.
Example: For N = 5, the 5th Fibonacci number is 5.
Q12. All Prime Numbers Problem Statement
Given an integer 'N', your task is to print all the prime numbers that lie within the range from 2 to 'N' (inclusive).
Input:
Integer N
Output:
Prime numbers printed on separ...read more
Print all prime numbers within the range from 2 to N.
Iterate from 2 to N and check if each number is prime
A prime number is a number greater than 1 that has no positive divisors other than 1 and itself
Use a nested loop to check divisibility by numbers less than the current number
Q13. Nth Fibonacci Number Problem
Calculate the Nth term in the Fibonacci sequence using the formula: F(n) = F(n-1) + F(n-2)
where F(1) = F(2) = 1
.
Given a number N, determine the Nth Fibonacci number.
Input:
N
Outp...read more
Calculate the Nth Fibonacci number using the given formula and constraints.
Implement a function to calculate the Nth Fibonacci number using the formula F(n) = F(n-1) + F(n-2) with base cases F(1) = F(2) = 1.
Use dynamic programming or recursion to efficiently compute the Fibonacci number for large N values.
Ensure the input N is within the constraints 1 <= N <= 10000.
Example: For N = 5, the output should be 5 as the 5th Fibonacci number is 5.
Write a SQL query to join two tables on a common attribute and select matching records.
Use the JOIN keyword to combine tables A and B on the common attribute ID
Specify the common attribute in the ON clause of the JOIN
Select the desired columns (ID_NAME) from the joined tables
Race horses in groups of 5, then race the winners to determine the top 3 fastest horses.
Divide the 25 horses into 5 groups of 5 horses each.
Race the horses in each group to determine the fastest horse in each group.
Race the winners from each group to determine the top 3 fastest horses.
Q16. How to convert a string containing a number into integer without using inbuilt function?
Convert string to integer without using inbuilt function
Iterate through each character and multiply by 10 and add the integer value of the character
Use ASCII values to convert character to integer
Handle negative numbers separately
Q17. What is right outer join and it's use in real world scenario
Right outer join is a type of join operation that returns all the rows from the right table and the matching rows from the left table.
Right outer join is denoted by the RIGHT JOIN keyword in SQL.
It is used to combine rows from two tables based on a related column.
In the result set, unmatched rows from the right table will have NULL values for the columns of the left table.
A real-world scenario for using a right outer join is when analyzing customer data and sales data. The ri...read more
To determine which switch controls which bulb with only one entry to the bulb room.
Turn on the first switch and leave it on for a few minutes, then turn it off.
Turn on the second switch and enter the room.
The bulb that is on corresponds to the second switch, the bulb that is off and warm corresponds to the first switch, and the bulb that is off and cold corresponds to the third switch.
Essential UNIX commands include ls, cd, pwd, mkdir, and rm.
ls - list directory contents
cd - change directory
pwd - print working directory
mkdir - make directory
rm - remove files or directories
Primary key uniquely identifies a record in a table, while unique key ensures no duplicate values in a column.
Primary key is used to uniquely identify each record in a table
Primary key does not allow NULL values
Unique key ensures that all values in a column are unique
Unique key allows NULL values, except for the column with unique constraint
A table can have only one primary key, but multiple unique keys
Left Outer Join includes all records from the left table and matching records from the right table. Right Outer Join includes all records from the right table and matching records from the left table.
Left Outer Join returns all records from the left table and the matched records from the right table. Unmatched records from the right table will have NULL values.
Right Outer Join returns all records from the right table and the matched records from the left table. Unmatched reco...read more
To find the second highest salary in a table, you can use a SQL query with the ORDER BY and LIMIT clauses.
Use a SQL query to select the distinct salaries in descending order: SELECT DISTINCT salary FROM table_name ORDER BY salary DESC
Use the LIMIT clause to retrieve the second row: LIMIT 1,1
Combine both queries to find the second highest salary: SELECT DISTINCT salary FROM table_name ORDER BY salary DESC LIMIT 1,1
Run time polymorphism in C++ allows objects of different classes to be treated as objects of a common parent class.
Run time polymorphism is achieved through virtual functions and function overriding.
It allows a function to behave differently based on the object it is called on.
Example: Using a base class pointer to call a virtual function that is overridden in a derived class.
Use the 3-liter and 5-liter cans to measure exactly 4 liters of water.
Fill the 3-liter can and pour it into the 5-liter can, leaving 2 liters in the 3-liter can.
Empty the 5-liter can, then pour the 2 liters from the 3-liter can into the 5-liter can.
Fill the 3-liter can again and pour it into the 5-liter can, which already has 2 liters, making it 4 liters.
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. Denormalization is the opposite process, adding redundancy to improve read performance.
Normalization involves breaking down a table into smaller tables and defining relationships between them to reduce redundancy.
Denormalization involves combining tables to reduce the number of joins needed for queries, improving read performance.
Normalization helps maintain data int...read more
Q26. What is recursion?Explain it graphically?How compiler executed recursion?
Recursion is a process in which a function calls itself repeatedly until a base condition is met.
Recursion involves breaking down a problem into smaller subproblems and solving them recursively.
It uses a stack to keep track of function calls and their parameters.
Examples include factorial, Fibonacci sequence, and binary search.
Compiler executes recursion by allocating memory for each function call and storing the return address and local variables on the stack.
It then pops th...read more
Singleton class in Java ensures that a class has only one instance and provides a global point of access to it.
Singleton class is implemented by making the constructor private to prevent instantiation from outside the class.
It provides a static method to access the single instance of the class.
The instance is created only once and reused throughout the application.
Example: Logger class in Java can be implemented as a Singleton to ensure only one instance is used for logging.
A friend function in C++ is a function that is not a member of a class but has access to the private and protected members of the class.
Friend functions are declared inside a class with the keyword 'friend'.
They can access private and protected members of the class they are friends with.
Friend functions are not member functions of the class.
Example: friend void displayDetails(Student);
Q29. What is python and constructer ,arrays,data structures
Python is a high-level programming language known for its simplicity and readability. Constructors are special methods used to initialize objects in classes.
Python is a versatile programming language used for web development, data analysis, artificial intelligence, and more.
Constructors in Python are special methods with the __init__() function that initialize objects when they are created.
Arrays in Python are data structures that can hold multiple values of the same type. Th...read more
Q30. Swap two character variables without using third
Swapping two character variables without using third
Use XOR operator to swap two variables without using third variable
Assign the XOR of both variables to the first variable
Assign the XOR of the first variable and second variable to the second variable
Q31. Write any program of recursion and explain it using stack frames?
A program demonstrating recursion using factorial function.
Recursion is a technique where a function calls itself.
Factorial function is a classic example of recursion.
Each recursive call creates a new stack frame.
The base case is when the input is 1, and the function returns 1.
The final result is the product of all the recursive calls.
Example: factorial(5) = 5 * factorial(4) = 5 * 4 * factorial(3) = ... = 5 * 4 * 3 * 2 * 1 = 120.
Garbage collector in Java is a built-in mechanism that automatically manages memory by reclaiming unused objects.
Garbage collector runs in the background to identify and remove objects that are no longer needed.
It helps prevent memory leaks and optimize memory usage.
Examples of garbage collectors in Java include Serial, Parallel, CMS, and G1.
Q33. which data structure is used in recursion?
The data structure used in recursion is a stack.
Recursion uses a stack data structure to keep track of function calls.
Each time a function is called, its parameters and local variables are pushed onto the stack.
When the function returns, the values are popped off the stack.
This allows the program to keep track of where it is in the recursive process.
Examples of recursive algorithms that use a stack include depth-first search and quicksort.
Q34. Difference between Primary key and Unique key
Primary key uniquely identifies a record in a table, while Unique key ensures uniqueness of a column.
Primary key can't have null values, Unique key can have one null value
A table can have only one Primary key, but multiple Unique keys
Primary key is automatically indexed, Unique key is not necessarily indexed
A static variable in C is a variable that retains its value between function calls.
Declared using the 'static' keyword
Retains its value throughout the program's execution
Useful for maintaining state across function calls
Q36. Write a program to check string is pallindrome or not
Program to check if a string is a palindrome or not.
Remove all spaces and convert to lowercase for case-insensitive comparison.
Compare the first and last characters, then move towards the center until all characters have been compared.
If all characters match, the string is a palindrome.
If any characters do not match, the string is not a palindrome.
Q37. What is a friend function
A friend function is a non-member function that has access to the private and protected members of a class.
Declared inside the class but defined outside the class scope
Can access private and protected members of the class
Not a member of the class but has access to its private members
Used to allow external functions to access and modify private data of a class
Can be declared as a friend in another class
Q38. What is garbage collection in java
Garbage collection in Java is an automatic memory management process.
It frees up memory by removing objects that are no longer in use.
It is performed by the JVM in the background.
It helps prevent memory leaks and improves performance.
There are different types of garbage collectors in Java, such as Serial, Parallel, CMS, and G1.
Example: int[] arr = new int[1000]; arr = null; // Garbage collector will remove the array from memory
Q39. Addition and Deletion of a node in binary tree?
Addition and Deletion of a node in binary tree
For addition, traverse the tree to find the appropriate position and add the new node as a leaf
For deletion, find the node to be deleted and replace it with its successor or predecessor
In case of deletion, if the node has two children, find the inorder successor and replace it with the node to be deleted
Q40. Definition of atoi function of C
atoi function converts a string to an integer in C.
The function takes a string as input and returns an integer.
Leading white spaces are ignored.
If the string contains non-numeric characters, the function stops conversion and returns the converted value.
The function returns 0 if the input string is not a valid integer.
Example: atoi('123') returns 123.
Q41. A program to print star pattern
A program to print star pattern
Use nested loops to print the pattern
The outer loop controls the number of rows
The inner loop controls the number of stars to be printed in each row
Use print() or println() function to print the stars
Q42. What is refrential integrity
Refrential integrity ensures that relationships between tables in a database remain consistent.
It is a database concept that ensures that foreign key values in one table match the primary key values in another table.
It prevents orphaned records in a database.
It maintains data consistency and accuracy.
For example, if a customer record is deleted, all related orders for that customer should also be deleted.
It is enforced through constraints such as foreign key constraints.
Q43. 2.what is singleton pattern
Singleton pattern is a design pattern that restricts the instantiation of a class to one object.
Used when only one instance of a class is needed throughout the application
Provides a global point of access to the instance
Implemented using a private constructor and a static method to return the instance
Example: Database connection, Logger, Configuration settings
Q44. Real time examples of Data structures?
Data structures are used to organize and store data in a computer program.
Arrays - used to store a collection of elements of the same data type
Linked Lists - used to store a collection of elements where each element points to the next element
Stacks - used to store a collection of elements where the last element added is the first element removed
Queues - used to store a collection of elements where the first element added is the first element removed
Trees - used to store hiera...read more
Q45. Which programming languages do you know.
I know multiple programming languages including Java, Python, and C++.
Java
Python
C++
Q46. 3.what is static variable
Static variable is a variable that retains its value even after the function execution is completed.
Declared with static keyword
Memory is allocated once and shared among all instances of the class or function
Can be accessed without creating an object of the class
Q47. Triggers and their types
Triggers are database objects that are automatically executed in response to certain events.
Triggers can be used to enforce business rules, audit changes, or replicate data.
There are two types of triggers: DML triggers and DDL triggers.
DML triggers are fired in response to DML statements (INSERT, UPDATE, DELETE).
DDL triggers are fired in response to DDL statements (CREATE, ALTER, DROP).
Q48. Libraries and packages in python
Libraries and packages in Python are reusable collections of code that provide functionality to perform specific tasks.
Libraries and packages help in reducing the amount of code that needs to be written from scratch
Popular libraries in Python include NumPy for numerical computing, Pandas for data manipulation, and Matplotlib for data visualization
Packages can be installed using package managers like pip or conda
Q49. Run time polymorphism in C++
Run time polymorphism is the ability of a program to determine the object type at runtime and call the appropriate method.
It is achieved through virtual functions and dynamic binding.
Allows for more flexible and extensible code.
Example: a base class Animal with virtual function makeSound() and derived classes Dog and Cat that override makeSound().
At runtime, if an Animal pointer points to a Dog object, calling makeSound() will execute the Dog's implementation.
Q50. Five linux commands you know
Five commonly used Linux commands
ls - list directory contents
cd - change directory
mkdir - make directory
rm - remove files or directories
grep - search for a pattern in a file
Q51. Write a query for delete
Query for deleting data from a database table.
Use the DELETE statement followed by the table name.
Add a WHERE clause to specify the condition for deleting specific rows.
Be careful when deleting data as it cannot be recovered.
Example: DELETE FROM customers WHERE customer_id = 1234;
Q52. Explain time complexity
Time complexity refers to the amount of time taken by an algorithm to run as the input size increases.
It measures the efficiency of an algorithm.
It is usually expressed in Big O notation.
An algorithm with a lower time complexity is more efficient than one with a higher time complexity.
Q53. Count the number of vowels in a string
Count the number of vowels in a given string
Iterate through each character in the string and check if it is a vowel (a, e, i, o, u)
Maintain a count of vowels encountered
Return the total count of vowels in the string
Q54. Write a code for copy constructor
A copy constructor is a special type of constructor which creates a new object as a copy of an existing object.
Ensure the copy constructor has the same signature as the default constructor.
Allocate memory for the new object and copy the values from the existing object.
Handle deep copy vs shallow copy based on the object's data types.
Q55. What is a copy constructor
A copy constructor is a special type of constructor in object-oriented programming that creates a new object as a copy of an existing object.
Creates a new object by copying the attributes of an existing object
Used to initialize a new object with the values of an existing object
Helps in creating deep copies of objects to avoid shallow copy issues
Q56. Explain Oops in java?
Object-oriented programming paradigm in Java focusing on objects and classes.
OOPs stands for Object-Oriented Programming.
It focuses on creating objects that interact with each other through classes.
Key principles include Inheritance, Encapsulation, Polymorphism, and Abstraction.
Example: Class Car { String color; void start() { //code here } }
Example: Car myCar = new Car(); myCar.color = 'red'; myCar.start();
Q57. Collection framework in java?
Collection framework in Java provides a set of interfaces and classes to store and manipulate groups of objects.
Includes interfaces like List, Set, and Map
Classes like ArrayList, LinkedList, HashSet, and HashMap implement these interfaces
Provides methods for adding, removing, and accessing elements in collections
Q58. joins and their use.
Joins are used in databases to combine rows from two or more tables based on a related column between them.
Joins are used to retrieve data from multiple tables based on a related column.
Common types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.
INNER JOIN returns rows when there is at least one match in both tables.
LEFT JOIN returns all rows from the left table and the matched rows from the right table.
RIGHT JOIN returns all rows from the right table and t...read more
Q59. 1. CountingSubstring in array
Count the number of occurrences of a specific substring in an array of strings.
Iterate through each string in the array and use a function to count occurrences of the substring.
Use a loop to go through each character in the string and check for matches with the substring.
Keep a count variable to track the number of occurrences found.
Q60. Detect cycle in LinkedList
Detect cycle in LinkedList by using Floyd's Tortoise and Hare algorithm.
Use two pointers, slow and fast, to traverse the LinkedList.
If there is a cycle, the fast pointer will eventually meet the slow pointer.
Initialize slow and fast pointers at the head of the LinkedList.
Move slow pointer by one step and fast pointer by two steps.
If fast pointer reaches the end of the LinkedList, there is no cycle.
Top HR Questions asked in Samavesh Marketing
Interview Process at Samavesh Marketing
Top Associate Software Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month