HYLAND | SDE INTERN | REMOTE
  1. Reversing Linked List
    There is a singly linkedlist of n integers where n is even. Perform the following operations on linkedlist.
    1.Select the segment of all n nodes and then reverse it.
    2.Reduce the segment size by 1 from each end and then reverse it.
    3.Repeat from step 2 until segment size reaches zero.
    Return a reference to the head of the final linked list.
    You are not allowed to use extra memory other than creating some new nodes required for implementations
    Example : -
    The initial linked list is
    1->5->2->7->8->3
    Entire list of n = 6 nodes is reversed.
    3->8->7->2->5->1
    |______________|
    Move the left and right pointers in one postion to define a segment with 4 nodes, then reverse those nodes.
    3->5->2->7->8->1
    ___|________|___
    Again move the pointers towards the center by 1 node each. Now there are two nodes to reverse.
    3->5->7->2->8->1
    ______|__|_______
    After moving the pointers this time the segment has 0 nodes and the iteration stops. Return a reference to the head of the final linked list 3->5->7->2->8->1
  2. Dominating xor
    For an array arr of n positive integers, count the unordered pairs (i,j) (0<=i<j<n) where arr[i] xor arr[j] > arr[i] and arr[j].
Comments (5)