Pages Networks Coding Questions

Jul 28, 2024

Notes on Pages Networks Coding Questions

Coding Questions Overview

3 questions were asked during the Internet Broadcasting round.

Question 1: Physics-Based Calculation

  • Topic: Work done by two persons.
  • Input Variables:
    • F1: Force applied by the first person.
    • D1: Displacement by the first person.
    • F2: Force applied by the second person.
    • D2: Displacement by the second person.
    • Network: Overall work done.
  • Formula:
    • Work done by the first person: W1 = F1 * D1
    • Work done by the second person: W2 = F2 * D2
    • Resultant work: Resultant = Network - (W1 + W2)
  • Assumptions:
    • Overall work is greater than the resultant work.
    • Resultant work will be an integer.

Sample Calculation

  • Given: Network = 50, F1 = 5, D1 = 2, F2 = 7, D2 = 3
  • Calculation:
    • W1 = 5 * 2 = 10
    • W2 = 7 * 3 = 21
    • Resultant = 50 - (10 + 21) = 19

Question 2: Truck Distance Calculation

  • Topic: Determine which truck is closer to the origin (0,0).
  • Input Variables:
    • Truck A: ax, ay (Coordinates)
    • Truck B: bx, by (Coordinates)
  • Formula:
    • Distance squared for truck A: D1 = ax*ax + ay*ay
    • Distance squared for truck B: D2 = bx*bx + by*by
  • Output: Return the minimum distance value.
  • Assumptions:
    • No need to calculate the square root; comparison can be done with squared values.
    • If distances are equal, return either.

Sample Calculation

  • Given: Truck A coordinates (12, 5), Truck B coordinates (12, 9)
    • D1 = 12*12 + 5*5 = 169
    • D2 = 12*12 + 9*9 = 225
    • Result: Return D1 since it is smaller.

Question 3: Linked List Digit Sum

  • Topic: Create a new linked list from the sum of two input linked lists.
  • Class Structure:
    • Node class with data and next properties.
    • Methods for creating the linked list and printing it.
  • Approach:
    • Convert linked list to integer.
    • Calculate the sum.
    • Create a new linked list from the sum digits, ensuring only single digits are kept at each node.
  • Edge Case: Handle carry-over if the sum exceeds 9.

Basic Implementation Steps

  1. Create a method to extract digits from linked list.
    • Traverse and concatenate digits.
  2. Perform the sum of the two concatenated numbers.
  3. Create a new linked list for the result.
  4. Reverse the linked list if necessary to maintain correct order of digits.
  5. Print or return the newly created linked list.

Complex Modifications

  • Make the question more complex by differing linked list lengths.
  • Allow multi-digit numbers in the linked lists.