Hello World

# Python code for "Hello World"

print("Hello!, I'm from crackforcrack")

Note: Please note that Python doesn't depend on the braces ( {} ), instead it uses indentation for its scope.

Crack Test


Count of Unique Integers based on Digit Sum

The program must accept an integer array of size N as the input. The program must print the count of integers after removing duplicate integers based on the digit sum of each integer as the output. That is if two integers have the same digit sum then it is a duplicate.
Boundary Condition(s):
2 <= N <= 100
1 <= Array Element Value <= 100000

Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains the count of integers after removing duplicate integers based on the digit sum of each integer.
Example Input/Output 1:
Input:
6
93 73 84 86 38 55 
Output:
4

Explanation:
The digit sum of 93 is 12
The digit sum of 73 is 10
The digit sum of 84 is 12
The digit sum of 86 is 14
The digit sum of 38 is 11
The digit sum of 55 is 10
Here there are two duplicate integers 84 and 55. After removing these 2 integers in the array the count of integers in the array will become 4.
Hence the count 4 is printed as the output.

Example Input/Output 2:
Input:
8
4 15 13 42 112 24 76 94 
Output:
3
#include
#include
int main()
{
  int n;
  scanf("%d",&n);
  int a[n],b[n];
  int i,s,j,cnt=0,r=0,sum=0;
  for(i=0;i
  scanf("%d",&a[i]);
  
  for(i=0;i
      sum=0;
    s=a[i];
    while(s>0){
        r=s%10;
        sum+=r;
        s/=10;
    }
    b[i]=sum;
  }
  for(i=0;i
  printf("%d ",b[i]);
  printf("\n");
  for(i=0;i
      if(b[i]!=-1){
          for(j=i+1;j
              if(b[i]==b[j]){
                  b[j]=-1;
              }
          }
      }
  }
  for(i=0;i
      if(b[i]!=-1)
      cnt++;
  }
  printf("%d",cnt);
}                                                                                                            
Daily Test 22.10.18
Diagonally Dominant or Not

The program must accept an integer matrix of size NxN as the input. The program must Yes if the matrix is left diagonally dominant. Else the program must print No as the output. A diagonal is said to be dominant if elements in the diagonal are greater than or equal to the sum of all other elements in their row.
Note: Consider the absolute value for calculating the sum.
Boundary Condition(s):
3 <= N <= 50

Input Format:
The first line contains the value of N.
The next N lines contain N integers separated by space(s).
Output Format:
The first line contains either 'Yes' or 'No'.

Example Input/Output 1:
Input:
3
3 -2 1
1 -3 -1
2 3 7
Output:
Yes

Explanation:
The diagonal element in the first row is 3.
|3| >= |-2| + |1| = |3| = |3|
The diagonal element in the second row is 3 (|-3| = 3).
|-3| >= |1| + |-1| = |-3| > |2|
The diagonal element in the third row is 7.
|7| >= |2| + |3| = |7| > |5|

Here, all the three left diagonal elements are greater than or equal to the sum of other two elements in their row. So, it is diagonally dominant.
Hence Yes is printed.

Example Input/Output 2:
Input:
4
4 -1 -1 -1
2 -6 2 3
1 2 4 1
2 3 1 -5
Output:

No
#include<stdio.h>
#include <stdlib.h>
int main()
{
    int i,j,n,cnt=0;
    scanf("%d",&n);
    int ar[n];
    for(i=0;i<n;i++)
    scanf("%d",&ar[i]);
    
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(ar[i]>ar[j])
            cnt++;
        }
    }
    printf("%d",cnt);
}                                                                                                                RunCode
Daily Test 20.10.18
 Count of Sorted Pairs
The program must accept an integer array of size N as the input. The program must print the count of pairs in the array so that the integers in the pair are sorted in descending order as the output. Boundary Condition(s): 1 <= N <= 100 Input Format: The first line contains the value of N. The second line contains N integers separated by space(s). Output Format: The first line contains the count of pairs in the array based on the condition mentioned above. Example Input/Output 1: Input: 5 2 8 7 5 6 Output: 5 Explanation: The pairs which satisfy the given conditions are (8, 7), (8, 5), (8, 6), (7, 5) and (7, 6). The count of pairs is 5. Hence the output is 5 Example Input/Output 2: Input: 7 51 56 5 25 75 38 73 Output: 8Code in C --> RunCode
#include<stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,n,cnt=0;
    scanf("%d",&n);
    int ar[n];
    for(i=0;i<n;i++)
    scanf("%d",&ar[i]);
    
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(ar[i]>ar[j])
            cnt++;
        }
    }
    printf("%d",cnt);

}                                                                                                                 RunCode
Daily Test 15.10.18
X Lines Integers Pattern
The program must accept two integers N and X as the input. The program must print the desired pattern as shown in the Example Input/Output sections.
Boundary Condition(s):
1 <= N <= 100
1 <= X <= 10
Example Input/Output 1:
Input:
8 5
Output:
8 
16 17 
24 25 26 27 
32 33 34 35 36 37 38 39 
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 

Example Input/Output 2:
Input:
9 3
Output:
9 
18 19 
27 28 29 30 
36 37 38 39 40 41 42 43  
Code in C --> Run Code
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,x;
    scanf("%d %d",&n,&x);
    for(int i=0;i<x;i++)
    {
        int t=n*(i+1);
        for(int j=0;j<pow(2,i);j++)
        {
            printf("%d ",t++);
        }
        printf("\n");
    }
}
Daily Test 12.10.18
Horizontal and Vertical Zig - Zag
The program must accept an integer N as the input. The program must print the desired pattern as shown in the Example Input/Output section.
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains the value of N.
Output Format:
The first N lines contain the desired pattern as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
5
Output:
1 2 3 4 5
2 9 8 7 6
3 8 10 11 12
4 7 11 14 13
5 6 12 13 15

Example Input/Output 2:
Input:
8
Output:
1 2 3 4 5 6 7 8
2 15 14 13 12 11 10 9
3 14 16 17 18 19 20 21
4 13 17 26 25 24 23 22
5 12 18 25 27 28 29 30
6 11 19 24 28 33 32 31
7 10 20 23 29 32 34 35
8 9 21 22 30 31 35 36Code in C -->                                                                                   Run Code 
#include<stdio.h>
#include <stdlib.h>

int main()
{
  int n,a=1;
  scanf("%d",&n);
  int i,j,k=1;
  int arr[n][n];
  for(i=0;i<n;i++)
  {
      if(i%2==0)
      {
          for(j=0;j<n;j++)
          {
              if(i<=j)
              {
                  arr[j][i]=a;
                  a+=1;
              }
          }
      }
      else
      {
          for(j=n-1;j>0;j--)
          {
              if(i<=j)
              {
                  arr[j][i]=a;
                  a++;
              }
          }
      }
  }
  int ar[n][n];
  for(i=0;i<n;i++)
    {
        for(j=0;j<i;j++)
        {
            printf("%d ",arr[i][j]);
        }
         ar[i][i]=arr[i][i];
         for(int p=0;p<i;p++)
         printf("");
        for(j=0;j<n-i;j++)
        {
            if(i%2==0)
            printf("%d ",ar[i][i]++);
            else
            printf("%d ",ar[i][i]--);
        }
        printf("\n");
    }
  return 0;
}                                                                                                                  Run Code
Daily Test 12.10.18
Two String Reverse Interlace Pattern
Two string values of equal length are passed as the input to the program. The program must print the desired pattern as shown in the Example Input/Output sections.
Boundary Condition(s):
1 <= Length of each string <= 1000

Example Input/Output 1:
Input:
min max
Output:
mxianm

Example Input/Output 2:
Input:
good real
Output:
gloaoedrCode in C -->                                                                                         Run Code
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
  char s1[1000],s2[1000];
  scanf("%s %s",s1,s2);
  int l=strlen(s1);
  for(int i=0;i<2*l;i++)
  {
        printf("%c",s1[i]);
        printf("%c",s2[l-1-i]);
  }
 }                                                                                                                  Run Code
1. Find n-th term of series 1, 3, 6, 10, 15, 21…
Given a number N, find the Nth term in the series 1, 3, 6, 10, 15, 21…
Input : The first line of input contains a positive integer T denoting the number of testcases. For each test case, there will be a single line containing an integer N.
Output: 
For each testcase, print the Nth term.
Constraints: 1 <= T <= 100 1 <= N <= 1000
Examples: Input: 
2
3 4
Output: 6 10










Hack Solutions


Pattern - Star Pyramid

C program to print following pyramid pattern of stars n=5
     *
  * * *
* * * * *
Sample Input 1 5 Sample Output 1
  * 
* * * 
* * * * *
Input Format
Input contains n
Constraints
1 <= n <= 20
Output Format
Print the pattern
Sample Input 0
5
Sample Output 0
        * 
      * * * 
    * * * * * 
  * * * * * * * 
* * * * * * * * * 
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { int n,i,j,k; scanf("%d",&n); for(i=0;i<n;i++) { for(k=0;k<n-1-i;k++) printf(" "); for(j=0;j<=i;j++) printf("* "); for(j=0;j<i;j++) printf("* "); printf("\n"); } return 0; } Run Code 

Compete Cell
There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbour). Each day, for each cell, if its neighbours are both active or both inactive, the cell becomes inactive the next day, otherwise it becomes active the next day.
Assumptions: The two cells on the ends have single adjacent cell, so the other adjacent cell can be assumed to be always inactive. Even after updating the cell state. consider its previous state for updating the state of other cells. Update the cell information of all cells simultaneously. Write a function cellCompete which takes takes one 8 element array of integers cells representing the current state of 8 cells and one integer days representing the number of days to simulate. An integer value of 1 represents an active cell and value of 0 represents an inactive cell.
Sample Input 1 1 0 0 0 0 1 0 0 1 Sample Output 1 0 1 0 0 1 0 1 0
Input Format
Input will have 8 array values and the no of days
Constraints
array size is 8 integers
Output Format
print the array

Sample Input 0
1 0 0 0 0 1 0 0
1
Sample Output 0
0 1 0 0 1 0 1 0 
#include <math.h>
#include <stdio.h>
int main(){
    int i,j,k,n,arr[8];
    for(i=0;i<8;i++)
        scanf("%d",&arr[i]);
    scanf("%d",&n);
    int arr1[8];
    for(i=0;i<n;i++)
    {
        if(arr[1]==0) arr1[0]=0;
        if(arr[1]==1) arr1[0]=1;
        if(arr[6]==0) arr1[7]=0;
        if(arr[6]==1) arr1[7]=1;
        for(k=1;k<=6;k++) 
        {
            if(arr[k-1]==arr[k+1])
                arr1[k]=0;
            else 
                arr1[k]=1;
        } 
        for(k=0;k<8;k++)
            arr[k]=arr1[k];
    }
    for(i=0;i<8;i++)
        printf("%d ",arr[i]); 
    return 0;
}                                                          Run Code
Eliminate Repeated Elements
Given two positive integer arrays ary1 and arr2 of lengths len1 and len2 respectively. write a program to count the number of elements which are not common In the arrays.
The input to the function distinctElementCount of two arrays arr1 and arr2 and their lengths len1 and len2 respectively.
The function return the number of elements which are not common in both arrays.
Example.
arr1 = {1, 2,3, 4, 5, 6, 7, 8, 9, 10}, lent = 10
arr2 = {11, 12, 13, 4, 5, 6, 7, 18, 19, 20}, len2 = 10
The distinct elements are 1, 2, 3, 8, 9, 10, 11, 12, 13, 18, 19 and 20 so the function should return 12.
Sample Input 1 5 6 34 89 12 45 93 12 93 45 23 78 35 
Sample Output 1 5
Input Format
Input contains the length of the arrays and the values
Constraints
1 ≤ n ≤105
1 ≤ values ≤ 109
Output Format
Print the count
Sample Input 0
5 6
34 89 12 45 93
12 93 45 23 78 35
Sample Output 0
5
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
      
    int l1,l2,i,cnt=0;
    scanf("%d %d",&l1,&l2);
    
    int a[105],b[110];
    for(i=0;i<l1;i++)    
        scanf("%d",&a[i]);    
    for(i=0;i<l2;i++)
        scanf("%d",&b[i]);

    for(i=0;i<l1;i++)
        for(int j=0;j<l2;j++)
        {
          if(a[i]==b[j])
          {
              a[i]=-1;
              b[j]=-1;
          }
        }
     for(i=0;i<l1;i++)
         if(a[i]!=-1)
             cnt++;
     for(i=0;i<l2;i++)
         if(b[i]!=-1)
             cnt++;
    printf("%d",cnt);
}                                                          Run Code
GCD Of Two Numbers
Write a 'C' program to find the GCD of two numbers
Sample Input 1 28690 5126 Sample Output 1 2
Input Format
Input contains two integers separated by space
Constraints
1 ≤ n1,n2 ≤ 105
Output Format
print the GCD of two numbers

Sample Input 0
28690 5126
Sample Output 0
2
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int num1, num2; 
    scanf("%d %d", &num1, &num2);
    while(num1!=num2)
    {
    if (num1 > num2)    
        num1 = num1-num2;
    else    
        num2 = num2-num1; 
    }
    printf("%d ",num1);
    return 0;
}                                                                                            Run Code
Less than Key element
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

     int n,num,cnt=0;
    scanf("%d %d",&n,&num);
    int a[1000];
    for(int i=0;i<n;i++)
    {
            scanf("%d ",&a[i]);
         
    }
     for(int i=0;i<n;i++)
    {
         if(a[i]<num)
         {
cnt++;         }
    }
    printf("%d",cnt);
    return 0;
}                                                                               Run Code
4
Matrix Rotation
Write a program to rotate a matrix in 90 degree.
Case 1:
Flag = 1
Input:
2 3 1
4 6 3
5 4 2
Output: 5 4 2
4 6 3
2 3 1

Case 2:
Flag = 0
Input:
2 1
3 4
Output:
4 1
3 2
Sample Input 1 3 3 1 2 3 1 4 6 3 5 4 2 Sample Output 1 5 4 2 4 6 3 2 3 1
Input Format
Input contains rowCount , columnCount, flag value and the array value
Constraints
1 ≤ array_size ≤ 1000
Output Format
print the rotated array
Sample Input 0
3 3 1
2 3 1
4 6 3
5 4 2
Sample Output 0
5 4 2 
4 6 3 
2 3 1             
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() 
{
    int n1,n2,i,j,a[1000][1000],flag;
    scanf("%d %d %d",&n1,&n2,&flag);
    for(i=0;i<n1;i++)
        for(j=0;j<n2;j++)
            scanf("%d",&a[i][j]);
            
    if(flag==1)
    {
     for(i=0;i<n1;i++){
        for(j=n2-1;j>=0;j--){
            printf("%d ",a[j][i]);
        }
         printf("\n");
     }
    }
    if(flag==0)
    {
     for(i=n1-1;i>=0;i--){
        for(j=0;j<n1;j++) {       
            printf("%d ",a[j][i]); 
        }
         printf("\n");
     }
     }
    return 0;
}
                                                                                        Run Code
Increment matrix
You are given an initial value as s and dimensions of the increment matrix as m and n.
An increment matrix is the matrix whose elements are the incremented values of the initial
value s. N
For example -
if initial value s = 1 and dimesions are: m=3,n=3
Increment Matrix would be:
1 2 3
4 5 6
7 8 9
Multiply the original increment matrix with its transpose.
The input to the method transposeMultMatrix shall consist of
the initial value s and the dimensions of the increment matrix m and n (s, m and n all
should be positive integers).
The method should return a 2-dimesional matrix for the multiplication matrix.
Sample Input 1 1 3 3 Sample Output 1 14 32 50 32 77 122 50 122 194 Sample Input 2 4 3 2 Sample Output 2 41 59 77 59 85 111 77 111 145
Input Format
Input contains rowCount,colCount and the array values
Constraints
1 ≤ array_size ≤ 1000
Output Format
Print the array

Sample Input 0
3 3
1 2 3
4 5 6
7 8 9
Sample Output 0
1 4 7 
2 5 8 
3 6 9    
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

    int n1,n2;
    scanf("%d %d",&n1,&n2);
    int a[n1][n2];
    for(int i=0;i<n1;i++)
    {
        for(int j=0;j<n2;j++)
        {
            scanf("%d ",&a[i][j]);
        }
    }
     for(int i=0;i<n2;i++)
    {
        for(int j=0;j<n1;j++)
        {
            printf("%d ",a[j][i]);
        }
         printf("\n");
    }
    return 0;
}                                                       Run Code
Merge Linked Lists
Merge two sorted singly linked lists into one sorted list
Sample Input 1 22 15 6 5 27 1 8 18 42 16 2 -1 28 25 41 12 22 4 38 26 30 24 11 31 -1 Sample Output 1 1 2 4 5 6 8 11 12 15 16 18 22 22 24 25 26 27 28 30 31 38 41 42

Input Format
Given two lists , -1 denotes the end
Constraints
nil
Output Format
Print the list

Sample Input 0
22 15 6 5 27 1 8 18 42 16 2  -1
28 25 41 12 22 4 38 26 30 24 11 31 -1
Sample Output 0
1 2 4 5 6 8 11 12 15 16 18 22 22 24 25 26 27 28 30 31 38 41 42  
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int a[1000],b[1000],z,d;
    for(int i=0;i<1000;i++)
    {
        scanf("%d",&z);
            if(z!=-1)
            {
                a[i]=z;
                d=i;
            }
        else
            i=1000;
    }
    for(int i=d+1;i<1000;i++)
    {
        scanf("%d",&z);
            if(z!=-1)
            {
                a[i]=z;
                d=i;
            }
          else
            i=1000;
    }
    for(int i=0;i<=d;i++)
    {
        for(int j=i;j<=d;j++)
        {
            if(a[i]>a[j])
            {
                int t=a[i];
                a[i]=a[j];
                a[j]=t;
            }
            
        }
    }
    for(int i=0;i<=d;i++)
        printf("%d ",a[i]);
    return 0;
}                                                          Run Code
Merge Sort Using Pointers
Write a program to merge sort using pointers
Apply merge sort to sort the values
Sample Input 1 5 78 64 23 6 93 Sample Output 1 6 23 64 78 93
Input Format
Input contains the size of the array and the values
Constraints
Array size may vary
Output Format
Print the sorted values

Sample Input 0
5
78 64 23 6
Sample Output 0
6 23 64 78 93 
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);
    
        for(int i=0;i<n;i++)
        {
          for(int j=i+1;j<n;j++)
          {
            if(arr[i]>arr[j])
            {
               int t=arr[i];
               arr[i]=arr[j];
               arr[j]=t;
            }
          }
        }
        for(int i=0;i<n;i++)
        printf("%d ",arr[i]);
        return 0;
}                                                         Run Code
PATTERN
PROGRAM TO PRINT NUMBER PATTERN 2
1 123 12345 1234567 123456789 1234567 12345 
123 1
Sample Input 1 
5 
Sample Output 1 
1 
123 
12345 
1234567 
123456789 
1234567 
12345 
123 
1
Input Format
Given N
Constraints
NIL
Output Format
Print the pattern

Sample Input 0
5
Sample Output 0
1
123
12345
1234567
123456789
1234567
12345
123
1
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
 int i, j, N;

    scanf("%d", &N);
    
    for(i=1; i<=N; i++)
    {
        for(j=1; j<=(i * 2 - 1); j++)
            printf("%d", j);
       printf("\n");
    }
    for(i=N-1; i>=1; i--)
    {
        for(j=1; j<=(i * 2 - 1); j++)
           printf("%d", j);
        printf("\n");
    }
    return 0;
}                                                          Run Code   
PROGRAM TO PRINT THE GIVEN NUMBER PATTERN
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n,i,j,k=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            k=i*j;
            if(k<100)
                printf("%d ",k);
            else
                printf("%d",k);
            if(k<10)
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n,i,j,k=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            k=i*j;
            if(k<100)
                printf("%d ",k);
            else
                printf("%d",k);
            if(k<10)
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}                                                                                         Run Code
PROGRAM TO PRINT THE GIVEN NUMBER PATTERN
1 
2 4 
3 6 9 4 8 12 16 5 10 15 20 25
Sample Input 1 
5 
Sample Output 1 
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25
Input Format
Given n
Constraints
NIL
Output Format
Print the pattern
Sample Input 0
5
Sample Output 0
1  
2  4  
3  6  9  
4  8  12 16 
5  10 15 20 25 
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n,i,j,k=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            k=i*j;
            if(k<100)
                printf("%d ",k);
            else
                printf("%d",k);
            if(k<10)
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}                                                      Run Code        
13. Get Integer Input from User
print("Enter '0' for exit.");
val = int(input("Enter any number: "));
if val == 0:
    exit();
else:
    print("You have just entered:",val);
Output :
Enter '0' for exit.
Enter any number: You have just entered: 4
14. Add Two Numbers in Python
print("Enter '0' for exit.");
print("Enter two numbers: ");
val1 = int(input());
val2 = int(input());
if val1 == 0:
    exit();
else:
    sum = val1 + val2;
    print("Sum of the given two number:",sum);
Output :
Enter '0' for exit.
Enter two numbers: 
Sum of the given two number: 13

7. Strings in Python
a = "S CraCkcoder"
print(a)
b = input()
print(b)
c = input("Enter Your Name:")
print(c)
d = str(input("Enter Your Name:"))
print(d)
Output :
S CraCkcoder
CraCkcoder
Enter Your Name:sujeet
Enter Your Name:singh