Triangle Quest Python
You are given a positive integer N. Print a numerical triangle of height N-1 like the one below: 1 22 333 4444 55555 ...... Can you do it using only arithmetic operations, a single for loop and print statement? Use no more than two lines. The first line (the for statement) is already written for you. You have to complete the print statement. Note: Using anything related to strings will give a score of 0. Input Format: A single line containing integer, N. Constraints:
View Solution →Triangle Quest 2 Python
You are given a positive integer N. Your task is to print a palindromic triangle of size N. For example, a palindromic triangle of size 5 is: 1 121 12321 1234321 123454321 You can't take more than two lines. The first line (a for-statement) is already written for you. You have to complete the code using exactly one print statement. Note: Using anything related to strings will give a score of 0. Using more than one for-statement will give a score of 0. Input Format: A
View Solution →No Idea! Python
There is an array of n integers. There are also 2 disjoint sets, A and B, each containing m integers. You like all the integers in set A and dislike all the integers in set B. Your initial happiness is o. For each i integer in the array, if i belons to A, you add 1 to your happiness. If i belong to B, you add -1 to your happiness. Otherwise, your happiness does not change. Output your final happiness at the end. Note: Since A and B are sets, they have no repeated elements. However, the array
View Solution →Symmetric Difference Python
Task: Given 2 sets of integers, M and N, print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either M or N but do not exist in both. Input Format: The first line of input contains an integer, M. The second line contains M space-separated integers. The third line contains an integer, N. The fourth line contains N space-separated integers. Output Format: Output the symmetric difference integers in ascending ord
View Solution →Set.add() Python
If we want to add a single element to an existing set, we can use the .add() operation. It adds the element to the set and returns 'None'. Example >>> s = set('HackerRank') >>> s.add('H') >>> print s set(['a', 'c', 'e', 'H', 'k', 'n', 'r', 'R']) >>> print s.add('HackerRank') None >>> print s set(['a', 'c', 'e', 'HackerRank', 'H', 'k', 'n', 'r', 'R']) Task: Apply your knowledge of the .add() operation to help your friend Rupal. Rupal has a huge collection of country stamp
View Solution →