Interesting question - TCS


  • Team myQ

    1_1560747018952_e54ccc76-8cba-4d57-a8bd-e2830f02a465.JPG 0_1560747018949_713359b6-90dc-48a2-8e94-c6cd1cc2f915.JPG



  • Did any one find soln for this....???..post it plz.. I'm done with this...


  • Team myQ

    Solution

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp2
    {
        class Program
        {
            static void Main(string[] args)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                int[] ar = new int[n];
                for(int i = 0; i < n; i++)
                {
                    ar[i] = Convert.ToInt32(Console.ReadLine());
                }
                int start = 0,first=0,second=1,third=0;
                int y = 0, x = 0, rightBoundary = 1, topBoundary = 1, leftBoundary = -1, bottomBoundary = -1;
                char move = 'r';
                int flag = 0;
     
               while (start < n)
                {
                    if (ar[start] == third)
                    {
                        Console.WriteLine(x + " " + y);
                        start++;
                    }
                    switch (move)
                    {
                        case 'r':
                            x++;
                            if (x == rightBoundary)
                            {
                                rightBoundary++;
                                move = 'u';
                            }
                            break;
    
                        case 'u':
                            y++;
                            if (y == topBoundary)
                            {
                                topBoundary++;
                                move = 'l';
                            }
                            break;
    
                        case 'l':
                            x--;
                            if (x == leftBoundary)
                            {
                                leftBoundary--;
                                move = 'd';
                            }
                            break;
    
                        case 'd':
                            y--;
                            if (y == bottomBoundary)
                            {
                                bottomBoundary--;
                                move = 'r';
                            }
                            break;
                    }
    
                    third = first + second;
                    if (flag > 0)
                    {
                        first = second;
                        second = third;
                    }
                    flag++;
    
                }
                Console.ReadLine();
            }
        }
    }
    


  • @Pankit said in Interesting question - TCS:

    Solution

    using System;
    
    • list item

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApp2
    {
    class Program
    {
    static void Main(string[] args)
    {
    int n = Convert.ToInt32(Console.ReadLine());
    int[] ar = new int[n];
    for(int i = 0; i < n; i++)
    {
    ar[i] = Convert.ToInt32(Console.ReadLine());
    }
    int start = 0,first=0,second=1,third=0;
    int y = 0, x = 0, rightBoundary = 1, topBoundary = 1, leftBoundary = -1, bottomBoundary = -1;
    char move = 'r';
    int flag = 0;

           while (start < n)
            {
                if (ar[start] == third)
                {
                    Console.WriteLine(x + " " + y);
                    start++;
                }
                switch (move)
                {
                    case 'r':
                        x++;
                        if (x == rightBoundary)
                        {
                            rightBoundary++;
                            move = 'u';
                        }
                        break;
    
                    case 'u':
                        y++;
                        if (y == topBoundary)
                        {
                            topBoundary++;
                            move = 'l';
                        }
                        break;
    
                    case 'l':
                        x--;
                        if (x == leftBoundary)
                        {
                            leftBoundary--;
                            move = 'd';
                        }
                        break;
    
                    case 'd':
                        y--;
                        if (y == bottomBoundary)
                        {
                            bottomBoundary--;
                            move = 'r';
                        }
                        break;
                }
    
                third = first + second;
                if (flag > 0)
                {
                    first = second;
                    second = third;
                }
                flag++;
    
            }
            Console.ReadLine();
        }
    }
    

    }

    ~~code_text~~