Posts

Showing posts with the label Matrix

Print a given matrix in spiral form

Image
  Problem Given a 2D array, print it in spiral form. Input:  {{1,    2,   3,   4},               {5,    6,   7,   8},              {9,   10,  11,  12},             {13,  14,  15,  16 }} Output: 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10  Explanation: The output is a matrix in a spiral format.  Input: { {1,   2,   3,   4,  5,   6},            {7,   8,   9,  10,  11,  12},           {13,  14,  15, 16,  17,  18}} Expected output: 1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11 Explanation : The output is a matrix in a spiral format.

Checking whether interval (a,b) is covered given 1-D list of coordinates

Question Given 1-D list of co-ordinates determine if interval (a,b) is covered Ex - [(2,5), (5,7),(1,4)] and interval = (1,6) return true Explanation - Points 1 to 6 lies in list of interval given 1 to 4. 2 to 5 and 5 to 7. [(1,4),(6,7),(2,5)] and interval - (1,6) return false Explanation - Distance between 5 to 6 is not covered in the list given so return false

Checking the overlap between given time duration[reviewed]

Problem You are given the list of time duration as below:  ( 3 , 4 ),   (10 , 13 ),  ( 5 , 6 ),  ( 5 , 7 )),  ( 7 , 9 ) Your algorithm should be able to tell whether there is overlap among these time durations.