Question 03: ------------- You are given a forest (it may contain a single tree or more than one tree) with N nodes. Each node is given an integer value 0 to (N-1). You have to find: ================== Nearest common ancestor of two given nodes x1 and x2. N can be very large. Aim for an algorithm with a time complexity of O(N). INPUT FORMAT ------------- An integer T, denoting the number of testcases, followed by 3T lines, as each testcase will contain 3 lines. First line of each testcase has the value of N. Second line of each testcase has list of N values where the number at index i is the parent of node i. The parent of root is -1. ( The index has the range [0, N-1] ). Third line for each testcase contains two integers within the range of [0,N-1] whose common ancestor you have to find. OUTPUT FORMAT ============== For each testcase given, output a single line that has the nearest common ancestor to two given nodes x1 and x2. If a common ancestor is not present then output '-1'. SAMPLE INPUT ------------- 2 6 5 -1 1 1 5 2 0 3 13 4 3 -1 -1 1 2 7 3 1 4 2 1 2 8 5 SAMPLE OUTPUT ================ 1 -1
Fresher Software Interview Questions
4,693 fresher software interview questions shared by candidates
tell about yourself?
java program to print patterns. aptitude round logical round.
Hourse question (English skill) Balls question (problem solving skill) Logical/Common sense questions flight crash question Java basics and java code
There were 2 rounds: 1. Aptitude 2. Technical cum HR Interview
difference in truncate delete explain fuctions,procedures, packages.
Tell me something about you
Tr round questions 1) joins 2)db connection 3)navigation 4) how to hold data in Java script variable
java I.o. package related questions hashmap hashlist array list all core java and logical question they asked
basic Java , multi threading , basic SQL, triggers, nested queries in aptitude retrieve data from database through servlet in programming test and date time programme and ping using multi threading
Viewing 1731 - 1740 interview questions