American Express
10+ Heights Incorporation Interview Questions and Answers
Q1. Maximum Non-Adjacent Subsequence Sum
Given an array of integers, determine the maximum sum of a subsequence without choosing adjacent elements in the original array.
Input:
The first line consists of an integer...read more
Find the maximum sum of a subsequence without choosing adjacent elements in an array.
Use dynamic programming to keep track of the maximum sum at each index, considering whether to include or exclude the current element.
At each index, the maximum sum can be either the sum of the current element and the element two positions back, or the sum at the previous index.
Iterate through the array and update the maximum sum accordingly.
Example: For input [3, 2, 7, 10], the maximum non-a...read more
Q2. Word Break Problem Statement
You are given a list of N
strings called A
. Your task is to determine whether you can form a given target string by combining one or more strings from A
.
The strings from A
can be u...read more
Given a list of strings, determine if a target string can be formed by combining one or more strings from the list.
Iterate through all possible combinations of strings from the list to form the target string.
Use recursion to try different combinations of strings.
Check if the current combination forms the target string.
Return true if a valid combination is found, otherwise return false.
Q3. All Paths From Source Lead To Destination Problem Statement
In a directed graph with 'N' nodes numbered from 0 to N-1, determine whether every possible path starting from a given source node (SRC) eventually le...read more
Determine if all paths from a source node lead to a destination node in a directed graph.
Check if there is at least one path from source to destination.
If a node has no outgoing edges, it should be the destination.
Ensure the number of paths from source to destination is finite.
Traverse the graph to validate all paths lead to the destination.
Q4. Find All Anagrams Problem Statement
Given a string STR and a non-empty string PTR, identify all the starting indices of anagrams of PTR within STR.
Explanation:
An anagram of a string is another string that can...read more
Given a string STR and a non-empty string PTR, find all starting indices of anagrams of PTR within STR.
Create a frequency map of characters in PTR.
Use sliding window technique to check anagrams in STR.
Return the starting indices of anagrams found.
Q5. Ninja And The Tree Problem Statement
Ninja, while learning Binary Search Trees (BST), accidentally swapped two nodes in her self-constructed BST. Your task is to help Ninja by correcting the BST so that all pro...read more
The task is to correct a Binary Search Tree by swapping two nodes in the tree.
Parse the input level order tree and construct the BST
Identify the two nodes that are swapped incorrectly
Swap the values of the incorrectly swapped nodes to correct the BST
Return the corrected BST in level order form
Q6. Maximum Sum With Specific Difference Problem Statement
Given an array of integers and a number 'K', your task is to find the maximum possible sum of disjoint pairs of numbers where the absolute difference betwe...read more
Find maximum sum of disjoint pairs with absolute difference less than K in an array.
Iterate through the array and sort it.
Find all possible disjoint pairs with absolute difference less than K.
Calculate the sum of these pairs to get the maximum sum.
A loop in a linked list can be detected using Floyd's Cycle Detection Algorithm.
Use two pointers - slow and fast, where slow moves one step at a time and fast moves two steps at a time.
If there is a loop, the two pointers will eventually meet at some point within the loop.
To detect the start of the loop, reset one pointer to the head and move both pointers one step at a time until they meet again.
Q8. find if array of numbers, which are prime, using streams
Use streams to find prime numbers in an array
Use Java streams to filter out non-prime numbers from the array
Check if a number is prime by dividing it by all numbers less than its square root
Create a method to check if a number is prime
Q9. Spring java and how do you leverage in your project
I leverage Spring Java for dependency injection, MVC framework, and transaction management in my projects.
Utilize Spring's dependency injection to manage object dependencies and improve code maintainability
Leverage Spring MVC framework for building web applications with clean separation of concerns
Use Spring's transaction management to ensure data integrity and consistency in database operations
Q10. How to implement security in microservices
Implement security in microservices by using authentication, authorization, encryption, and monitoring.
Use authentication mechanisms like OAuth, JWT, or API keys to verify the identity of clients accessing the microservices.
Implement authorization controls to define what actions users can perform within the microservices.
Encrypt data in transit and at rest using protocols like HTTPS and TLS, and tools like Vault or AWS KMS.
Implement monitoring and logging to detect and respon...read more
Q11. A program to print 1 to n prime numbers
Program to print 1 to n prime numbers
Iterate from 2 to n and check if each number is prime
Use a function to check if a number is prime
Print the prime numbers found
More about working at American Express
Interview Process at Heights Incorporation
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month