Follow Quotesrain
  • Result
  • Today's Puzzle
    • Previous Puzzles
    • Prize & Rules
  • Discussion Board
    • Suggestion Board
    • Trending Articles
  • Maths Tricks
  • Placement Papers
    • Placement Questions
    • Interview Experience
    • Placed user Comment
    • Group Discussion
  • English APP
  • login
  • Result
  • Today's Puzzle
    • Previous Puzzles
    • Prize & Rules
  • Discussion Board
    • Suggestion Board
    • Trending Articles
  • Maths Tricks
  • Placement Papers
    • Placement Questions
    • Interview Experience
    • Placed user Comment
    • Group Discussion
  • Walkins
    • Corporate Job Exam
    • Government Job Exam
    • Entrance Exam
  • Training
    • Internship
  • Placement Questions
  • /
  • C
  • /
  • Programming
  • /
  • Variables

C Programming - Variables Technical Interview Questions

C Select Another Category Variables Select Another Topic

Programming and Technical

  • Android 118
  • ASP.NET 60
  • C 459
  • C++ 448
  • DATA STRUCTURE 66
  • DBMS 77
  • ELECTRONICS 39
  • Java 260
  • OOPs Concepts 117
  • Operating Syst 103
  • RDBMS 109
  • UNIX 70

C Question Topics

    Category (16)

    General Ability (2)

  • General Knowledge (2)
  • HR Interview (2)

  • Interview (2)
  • Logical Reasoning (9)

  • Coding Decoding (2)
  • Cryptography (1)
  • General Mental Ability (1)
  • Letter Series (1)
  • Mathematical Reasoning (1)
  • Missing Character (1)
  • Seating Arrangement (1)
  • Numerical Ability (12)

  • Age Problem (1)
  • Algebra (1)
  • Alligation or Mixture (1)
  • Data Interpretation (1)
  • Height and Distance (1)
  • Percentage (2)
  • Ratio and Proportion (1)
  • Time Distance and Speed (1)
  • Programming (218)

  • Arrays (15)
  • Basics (8)
  • Database (6)
  • Definition (25)
  • Functions (4)
  • Output (42)
  • Program (85)
  • Puzzles (1)
  • Technical (24)
  • Variables (1)
  • Verbal Ability (3)

  • Antonyms (1)
  • Miscellaneous (1)
  • Spotting Errors (1)
Keep an EYE (0)
Solved Question (0) UnSolved Question (1)
Pages: 11
Advertisements

(#M40166240) C QUESTION juspay interview question Keep an EYE Keep an eye puzzle Keep an eye puzzle

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:
The depth of forest at which maximum number of nodes are present.
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 2T lines, as each testcase will contain 2 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] ).

OUTPUT FORMAT

For each testcase given, output a single line that has the depth of forest at which maximum number of nodes are present. If multiple depths has same number of nodes, then deepest depth should be selected.

SAMPLE INPUT

2

6

5 -1 1 1 5 2

13

4 3 -1 -1 1 2 7 3 1 4 2 1 2



SAMPLE OUTPUT

3

1

Asked In C Mohamed yasin (3 years ago)
Unsolved Read Solution (1)
Is this Puzzle helpful?   (33)   (41) Submit Your Solution Variables
Keep an EYE (0)
Solved Question (0) UnSolved Question (1)
Pages: 11
  • Login
  • Register

Resend

Sponsored Links

Advertisements

Challenger of the Day

no image
Dimple
India
Punjab
Time: 00:01:33
Points
19

Maths Quotes

MATHEMATICS IS THE ONLY SUBJECT WHICH DEVELOPS OUR LOGICAL THINKING

pavanchandra

Stop the "differentiation" in society, it is "integration" what we need.

ChaZ-E

Placed User Comments

M4Math helped me a lot.

Vipul Chavan 2 years ago

Thanks m4 maths for helping to get placed in several companies.
I must recommend this website for placement preparations.

yash mittal 3 years ago
  • 2471K+Registerd user
  • 1730K+Engineers
  • 741K+MBA Asprirant
  • 3K+Enginnering College
  • 250+Company Exam
  • 150K+Interview Questions
  • Site Links
  • Home
  • Result
  • Today's Puzzle
  • Discussion Board
  • Maths Tricks
  • Advertise with us
  • Contact Us
  • Useful Info
  • Maths Quotes
  • Previous Puzzles
  • Prize
  • Privacy Policy
  • Disclaimer and Copyright
  • Terms and Conditions
  • Sitemap
  • Placement papers
  • TCS Placement Paper
  • HCL Placement Paper
  • INFOSYS Placement Paper
  • IBM Placement Paper
  • SYNTEL Placement Paper
  • TECHNICAL Interview
  • HR Interview
All rights are reserved to @m4maths.com