FICO
Travelurcity Interview Questions and Answers
Q1. Sort array containing 0s, 1s and 2s
Sort an array of 0s, 1s, and 2s in linear time complexity.
Use three pointers to keep track of the positions of 0s, 1s, and 2s.
Traverse the array and swap elements to their respective positions.
Time complexity: O(n), Space complexity: O(1).
Q2. Why is string immutable in java?
String is immutable in Java to ensure security, thread safety, and optimization.
Immutable strings are thread-safe as they cannot be modified concurrently by multiple threads.
String pooling allows Java to optimize memory usage by reusing common string literals.
Immutable strings prevent security vulnerabilities like SQL injection attacks.
Q3. Abstract class vs interface
Abstract class is a class that cannot be instantiated, while an interface is a contract that a class must implement.
Abstract classes can have implemented methods, while interfaces cannot
A class can implement multiple interfaces, but can only inherit from one abstract class
Interfaces are used for achieving multiple inheritance in Java
Abstract classes are used for creating a base class for other classes to inherit from
Example of abstract class: public abstract class Animal { pu...read more
Q4. Spiral order traversal of BST.
Spiral order traversal of BST
Use two stacks to traverse the tree in a spiral order
Push the root node into the first stack
While the first stack is not empty, pop a node and print its value
Push its left and right children into the second stack
Once the first stack is empty, swap the stacks and repeat the process
Continue until both stacks are empty
Q5. Hashmap vs hashset
Hashmap is a key-value pair data structure while Hashset is a set of unique values.
Hashmap allows duplicate values but not duplicate keys.
Hashset does not allow duplicate values.
Hashmap is implemented using a combination of hash table and linked list.
Hashset is implemented using only a hash table.
Example of Hashmap: {1:'one', 2:'two', 3:'three'}
Example of Hashset: {'apple', 'banana', 'orange'}
Q6. Arraylist vs hashmap
ArrayList is a resizable array while HashMap is a key-value pair data structure.
ArrayList is ordered and allows duplicates while HashMap is unordered and does not allow duplicate keys.
ArrayList is accessed by index while HashMap is accessed by key.
ArrayList is suitable for storing and accessing elements sequentially while HashMap is suitable for fast lookup of values by key.
Example: ArrayList - List
names = new ArrayList<>(); names.add("John"); names.add("Jane"); Example: Hash...read more
Top Software Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month