Sunday, September 23, 2018

Pattern

  • Problem Description

    Print the following pattern :

    If N = 1

    1

    If N = 2

    2 2 2
    2 1 2
    2 2 2

    If N = 3

    3 3 3 3 3
    3 2 2 2 3
    3 2 1 2 3
    3 2 2 2 3
    3 3 3 3 3

    and so on.
  • CODING ARENA
  • #include <stdio.h>

    int main(){
        int i, j, n;
        int number_to_print;


        scanf("%d", &n);
        number_to_print = n;

        for(i = 0; i < n; i++){
            //--next_number_to_repeat;
            number_to_print = n;

            for(j =0 ; j< (2*n-1); j++){

                printf("%d ", number_to_print);
                if( j < i   )   
                    --number_to_print;
                else if( j >  ( (n*2)- i -3  ) ) 
                    ++number_to_print;

            }   
            printf("\n");
        }   
    #if 1
        for(i = n-2; i >= 0; i--){
            number_to_print = n;

            for(j =0 ; j < (2*n-1); j++){

                printf("%d ", number_to_print);
                if( j < i   )   
                    --number_to_print;
                else if( j >  ( (n*2)- i -3  ) ) 
                    ++number_to_print;

            }   
            printf("\n");
        }   
            
    #endif
        return 0;

    }
  • Test Case 1

    Input (stdin)
    3
    
    
    Expected Output
    3 3 3 3 3 
    
    3 2 2 2 3 
    
    3 2 1 2 3 
    
    3 2 2 2 3 
    
    3 3 3 3 3
  • Test Case 2

    Input (stdin)
    2
    
    
    Expected Output
    2 2 2 
    
    2 1 2 
    
    2 2 2

34 comments:

  1. Given a sorted array of integers. Let N be the number of test cases. Let n be the number of elements of the given array. Destiny value is provided. Check whether the target value is located on the given sorted array, if it is so then return the index of the array else identify the position where the target value needed to be inserted. Print the index of the identified target value else return the index value where the elements to be inserted.
    INPUT FORMAT: Get the sorted array containing elements and the target value
    OUTPUT FORMAT: Print the index value of the target element if it exists else return the position where the target element is needed to be inserted.
    EXPLANATION: Get the sorted array containing elements and the target value. Now check whether the given target values lies on the given array if it so return the index value else return the index value where the target value to be inserted.

    ReplyDelete

  2. "Dark was deeply studying in the afternoon and came across a concept called as ""REVERSE OF A NUMBER"". He decided to design a program which can reverse any long numbers.
    At the end of afternoon, he started to code and finally end up with no results, so decided to ask you all for the help, he wanted you to design a very efficient method to reverse a number and say it as a EVEN or ODD.
    Confused, Simply print ""EVEN""(without quotes) if the reverse of the given number is even and print ""ODD""(without quotes) if the reverse of the given number is odd.
    Input:
    The first line contains T, the number of test cases. Followed by T lines each contains a single number.
    Output:
    For every test case print the ""EVEN""(without quotes) if reverse of GIVEN number is even else print ""ODD""(without quotes).
    Constraints:
    1<=T<=10000
    1<=N<=10100
    "

    ReplyDelete
  3. C program to find sum of following series
    1 + 3^2/3^3 + 5^2/5^3 + 7^2/7^3 + ... till N terms

    ReplyDelete
  4. Harsh and Akshara are playing the Game of Strings. This game is a simple one and is played as a team. Both the players of a team will be given a string respectively. At the end of this game, every team is required find out the length of the longest string S such that the strings given to each of the team members is a subsequence of S andS contains no vowels. Help Harsh and Akshara in finding out the required length.

    Input:
    Input consists of a single line containing two space separated strings.

    Output:
    The length of the longest string that satisfy the given conditions.

    Constraints:
    1 <= length of string <=5000 Explanation
    The required string is "ng". if the constraint of the string S not containing vowels is removed, this becomes the classical Longest Common Subsequence (LCS) problem. For readers who are not familiar with LCS problem, they are encouraged to go through the following link which explains the problem as well to how to come up with the solution.

    http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
    One can see that the LCS of the input two strings can never contain any vowels, hence, it is redundant to have vowels in the original string. Now, if we remove the vowels from the input strings, the problem is to find the length of the LCS of the edited strings. One can use the same approach described in the above wiki link to implement the solution.
    TEST CASE 1

    INPUT
    abbs aabbss
    OUTPUT
    3
    TEST CASE 2

    INPUT
    mango mango
    OUTPUT
    3

    ReplyDelete
  5. "Sum all the numbers of the array except the highest and the lowest element (the value, not the index!).
    (The highest/lowest element is respectively only one element at each edge, even if there are more than one with the same value!)
    Example:
    { 6, 2, 1, 8, 10 } => 16
    { 1, 1, 11, 2, 3 } => 6
    If array is empty, null or None, or if only 1 Element exists, return 0.
    TEST CASE 1

    INPUT
    5
    6 2 1 8 10
    OUTPUT
    16
    TEST CASE 2

    INPUT
    5
    1 1 11 2 3
    OUTPUT
    6

    ReplyDelete
    Replies
    1. I need answer for this sir ....plz post the answer sir

      Delete
  6. Write a program that will copy m consecutive characters from a string s1 beginning at position n into another string s2

    Refer sample Input and Output:
    1. The first input corresponds to the string input
    2. The Second Input corresponds to the number of characters to be copied
    3. The third input corresponds to the string index

    Sample Input 1:
    SRMUniversity
    5
    0
    Output 1:
    SRMUn

    Explanation:
    The String index starts from 0 and add five characters after that
    S=0
    R=1
    M=2
    U=3
    n=4

    Sample Input 2:
    SRMAPPLELAB
    6
    3

    Output:
    APPLEL


    Explanation:
    The String index starts from 3 and add six characters after that
    S=0
    R=1
    M=2
    A=3
    P=4
    P=5
    L=6
    E=7
    L=8
    A=9
    B=10

    Output: APPLEL
    TEST CASE 1

    INPUT
    SRMUniversity
    5
    0
    OUTPUT
    SRMUn
    TEST CASE 2

    INPUT
    SRMAPPLELAB
    6
    3
    OUTPUT
    APPLEL

    ReplyDelete
  7. You are given an N N grid initially filled by zeros. Let the rows and columns of the grid be numbered from 1 to N, inclusive. There are two types of operations can be applied to the grid:

    RowAdd R X: all numbers in the row R should be increased by X.
    ColAdd C X: all numbers in the column C should be increased by X.

    Now after performing the sequence of such operations you need to find the maximum element in the grid.
    Input

    The first line of the input contains two space separated integers N and Q denoting the size of the grid and the number of performed operations respectively. Each of the following Q lines describe an operation in the format described above.
    Output

    Output a single line containing the maximum number at the grid after performing all the operations.
    Constraints

    1 <= N <= 314159
    1 <= Q <= 314159
    1 <= X <= 3141
    1 <= R, C <= N

    TEST CASE 1

    INPUT
    2 4
    RowAdd 1 3
    ColAdd 2 1
    ColAdd 1 4
    RowAdd 2 1
    OUTPUT
    7
    TEST CASE 2

    INPUT
    3 2
    RowAdd 1 3
    ColAdd 2 1
    OUTPUT
    4

    ReplyDelete
  8. Radha is always interested to play with alphabets. She wants to constructs a alphabetical pyramid. Help her to design a C program that will assist her to do the task easily. Input format : Any alphabet say D Output format: A pyramid that starts with a single A on top, 2 B next, 3 Cs next and so on till the input alphabet D
    TEST CASE 1

    INPUT
    G
    OUTPUT
    A
    BB
    CCC
    DDDD
    EEEEE
    FFFFFF
    GGGGGGG
    TEST CASE 2

    INPUT
    B
    OUTPUT
    A
    BB

    ReplyDelete
  9. Devu has n weird friends. Its his birthday today, so they thought that this is the best occasion for testing their friendship with him. They put up conditions before Devu that they will break the friendship unless he gives them a grand party on their chosen day. Formally, ith friend will break his friendship if he does not receive a grand party on dith day.

    Devu despite being as rich as Gatsby, is quite frugal and can give at most one grand party daily. Also, he wants to invite only one person in a party. So he just wonders what is the maximum number of friendships he can save. Please help Devu in this tough task !!

    Input

    The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
    First line will contain a single integer denoting n.
    Second line will contain n space separated integers where ith integer corresponds to the day dith as given in the problem.
    Output

    Print a single line corresponding to the answer of the problem.

    Constraints

    1<= T <= 104
    1 <= n<= 50
    1 <= di<= 100

    Explanation
    Example case 1. Devu can give party to second friend on day 2 and first friend on day 3, so he can save both his friendships.

    Example case 2. Both the friends want a party on day 1, and as the Devu can not afford more than one party a day, so he can save only one of the friendships, so answer is 1.
    TEST CASE 1

    INPUT
    2
    2
    3 2
    2
    1 1
    OUTPUT
    2
    1
    TEST CASE 2

    INPUT
    2
    4
    3 2 1 4
    2
    6 9
    OUTPUT
    4
    2

    ReplyDelete
  10. Create a structure called College.

    struct College
    {
    char name[100];
    char city[100];
    int establishmentYear;
    float passPercentage;
    }

    The structure variable name "S1"

    Write a program to get the details of n colleges and to display their details, sorted by college name in ascending order.

    Input and Output Format:

    Refer sample input and output for formatting specification.
    All float values are displayed correct to 2 decimal places.
    All text in bold corresponds to input and the rest corresponds to output.

    Hint: The college name should be in Sorted or in Ascending Order
    College details are sorted based on their "Names" in ascending order

    In Test case 1:
    S comes before T (A B C D E F G H I J K L M N O P Q R S T)

    In Test case 2:
    A,K,S(A B C D E F G H I J K L M N O P Q R S T)

    Note: The structure variables, data members and structure name are CASE Sensitive.

    Follow the same case mentioned in the mandatory
    TEST CASE 1

    INPUT
    2
    SRMUniversity Chennai 1985 97.6
    TRPEngineeringCollege Trichy 1998 97.2
    OUTPUT
    Details of colleges
    Name:SRMUniversity
    City:Chennai
    Year of establishment:1985
    Pass percentage:97.6
    Name:TRPEngineeringCollege
    City:Trichy
    Year of establishment:1998
    Pass percentage:97.2
    TEST CASE 2

    INPUT
    3
    Karunyauniversity Coimbatore 1986 67.2
    SastraUniversity Trichy 1987 77.3
    Amritauniversity Coimbatore 1988 90.1
    OUTPUT
    Details of colleges
    Name:Amritauniversity
    City:Coimbatore
    Year of establishment:1988
    Pass percentage:90.1
    Name:Karunyauniversity
    City:Coimbatore
    Year of establishment:1986
    Pass percentage:67.2
    Name:SastraUniversity
    City:Trichy
    Year of establishment:1987
    Pass percentage:77.3

    ReplyDelete
  11. Ganapathy working as a professor in ABC college, have
    to get students three subjects points.

    so he planned to do one program to implement
    structure concept.

    Input

    3 3 5

    Output

    3 3 5
    TEST CASE 1

    INPUT
    3 3 5
    OUTPUT
    3 3 5
    TEST CASE 2

    INPUT
    3 3 6
    OUTPUT
    3 3 6

    ReplyDelete
  12. Write a C Program to compute the sum of all elements stored in an array using pointer
    TEST CASE 1

    INPUT
    10
    1 2 3 4 5 6 7 8 9 10
    OUTPUT
    55
    TEST CASE 2

    INPUT
    10
    7 7 7 7 7 7 7 7 7 7
    OUTPUT
    70

    ReplyDelete
  13. Write a program to subtract two double values using pointer

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output
    TEST CASE 1

    INPUT
    4
    5
    OUTPUT
    -1.00
    TEST CASE 2

    INPUT
    10
    6
    OUTPUT
    4.00

    ReplyDelete
  14. Any type of technical issue can be solved by our quickbooks support phone number usa 1800-901-6679.

    ReplyDelete
  15. Nice blog. Well we provide Quickbooks customer care number In such a situation, we recommend that you dial the toll-free 1800-986-4607. We have cerified customer executive to help you.

    ReplyDelete
  16. Nice Blog QuickBooks is one of the best accounting software which helps in managing your company’s finances and accounting. The products of QuickBooks are oriented towards small and medium-sized businesses. We are providing technical support in Quickbooks Customer Care Number Please call us our Toll-free Number + 1-800-986-4607.

    ReplyDelete
  17. Nice Blog If you need Quickbooks Support Phone Number California then you can dial +1-800-986-4591 for help and support. Our technical support team always provides you the best technical help.

    ReplyDelete
  18. Thanks For Sharing!
    Quickbooks application can easy to use. It is user friendly software if you are facing issue dial our Quickbooks Support in New York 1-800-986-4591.

    ReplyDelete
  19. Lost connection to your Data file or Can’t able to locate the Data File? No matter, how complex the issues would be. Get instant & easy solutions for your queries by contacting us, on Quickbooks Toll Free Phone Number 800-986-4607. We provide the best support service to the Quickbooks user.

    ReplyDelete
  20. Nice Blog ! Quickbooks is the widely used accounting software catering needs of industries. Though it is very simple to use yet like any other exclusive product, If you are facing issue you can take help from our experts by dialing our QuickBooks Error Support Phone Number 800-986-4607.

    ReplyDelete
  21. Nice Blog ! Our team is available every time for your help. They are carrying years of experience and can solve any QuickBooks error in a very short span of time. What are you waiting for now? Dial QuickBooks Payroll Support Phone Number 1-800-986-4607.

    ReplyDelete
  22. The main motive of the Big data banking analytics is to spread the knowledge so that they can give more big data engineers to the world.

    ReplyDelete
  23. I'M TOTALLY FREE FROM HEPATITIS B
      I’m Stephanie Brown, I was diagnosed with Hepatitis B 4 years ago, I lived in pain with the knowledge that I wasn't going to ever be well again. I have used several antiviral medications, but this could not fight the virus of me rather I got side effects of fever, muscle and joint pain. After  spending so much money on antiviral drugs but I never get better. I made research on the internet for herbal medicine. AS I was determined to get my lifestyle back and to be able to do things I am restricted from doing, I saw a lady’s post on how Herbal Dr. JAMES cured her of HIV with his herbal mix medicine. I contacted the same Doctor through his email....Drjamesherbalmix@gmail.com....we spoke, I told him all that I have been going through, and he told me not to worry that everything will be better again, so he prepared his herbal mix medicine and sent it to me through DHL courier company and told me the usage, after 21 days of completing the herbal medicine, I was totally free from Hepatitis B, I went to see a doctor for a blood test, After taking a sample of my blood for the test the result came out negative, I just can’t deny that I’m the happiest woman on earth this very moment, I’m so happy and thanks to Herbal Doctor JAMES,He also told me he cures  diseases   such as Alzheimer's disease, schizophrenia, Autism. Bipolar disorder,  Shingles, Melasma, Underactive thyroid, Melanoma, Cancer, Weak Erection, Wart Remover, HPV, Herpes, Fibromyalgia, HIV, Hepatitis b,Liver/Kidney Inflammatory, Epilepsy, Fibroid, Diabetes,COPD, Back pain, Nephrotic syndrome,Infertility.Cardiovascular diseases.lung diseases,Thyroid disorders ,PCOS,Contact him on his email and get rid of your diseases, he is a good  man  Email....Drjamesherbalmix@gmail.com

    ReplyDelete
  24. Given two non negative numbers X and Y.The task is calculate the sum of X and Y.If the number of digits in sum(X+Y) are equal to the number of digits in X,then print sum,else print X

    Constraints:
    1<=T<=500
    1<=|Digits in X,Y|<=100

    Input:

    The first line of input contains an integer T denoting the number of test cases.Then T test cases follow.Each test case contains two numbers X and Y.

    Output:
    For each test case, print the required answer


    ReplyDelete
  25. I am here to give my testimony about Dr Ebhota who helped me.. i want to inform the public how i was cured from (HERPES SIMPLEX VIRUS) by salami, i visited different hospital but they gave me list of drugs like Famvir, Zovirax, and Valtrex which is very expensive to treat the symptoms and never cured me. I was browsing through the Internet searching for remedy on HERPES and i saw comment of people talking about how Dr Ehbota cured them. when i contacted him he gave me hope and send a Herbal medicine to me that i took for just 2 weeks and it seriously worked for me, my HERPES result came out negative. I am so happy as i am sharing this testimony. My advice to you all who thinks that there is no cure for herpes that is Not true just contact him and get cure from Dr Ebhota healing herbal cure of all kinds of sickness you may have like (1) CANCER,(2) DIABETES,(3) HIV&AIDS,(4) URINARY TRACT INFECTION,(5) CANCER,(6) IMPOTENCE,(7) BARENESS/INFERTILITY(8) DIARRHEA(9) ASTHMA(10)SIMPLEX HERPES AND GENITAL(11)COLD SOREHERPES. he also cure my friend from cervical cancer Email: drebhotasoultion@gmail.com or whatsapp him on +2348089535482

    ReplyDelete
  26. Become a data science expert by joining AI Patasala’s Data Science Course in Hyderabad, where you can learn data science concepts with practical knowledge.
    Data Science Course Training Institute in Hyderabad with Placements

    ReplyDelete