Posts

Showing posts from May, 2021

function invertSubMatrix DC[01/06/2021]

function invertSubmatrix Daily Challenge [01/06/2021] IMPORTANT: Do not write the main() function as it is already defined. Example Input/Output 1: Input: 5 6 0 1 0 1 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 1 1 1 0 0 2 3 3 Output: 0 1 0 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 1 1 1 0 1 0 0 1 1 1 0 0 Explanation: Here K=3, so the size of the submatrix is 3x3. The position of the top-left cell is (2, 3). The submatrix is highlighted below. 0 1 0 1 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 1 1 1 0 0 After inverting the values in the submatrix, the matrix becomes 0 1 0 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 1 1 1 0 1 0 0 1 1 1 0 0 Example Input/Output 2: Input: 6 4 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 1 0 0 0 1 1 1 0 0 3 1 4 Output: 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1 1 void invertSubmatrix(int R, int C, int matrix[R][C], int sRow, int sCol, int K) {sRow--; sCol--; int eRow=sRow+K; int eCol=sCol+K; for(int i=sRow;i<eRow;i++) {     for(int j=sCol;j<eCol;j++)     {     ...

class Student DC[31/05/2021]

Define Class Student: Input: 3 Hector 95 Arjun 97 Rachel 82 5 5 10 Output: Hector:100 Arjun:100 Rachel:92 Explanation: 1st student: Hector 95 marks + 5 additional marks = 100 marks. 2nd student: Arjun 97 marks + 5 additional marks(a maximum of 3 marks can be added) = 100 marks. 3rd student: Rachel 92 marks + 10 additional marks = 92 marks. Example Input/Output 2: Input: 4 Oliver 100 Catherine 30 Deepa 95 Mambo 25 10 5 2 8 Output: Oliver:100 Catherine:35 Deepa:97 Mambo:33 CODE SNIPPET: class Student{     String name="";     int marks;     Student(String name,int marks)     {         this.name=name;         this.marks=marks;     }     public void addExtraMarks(int extraMarks)     {         this.marks+=extraMarks;         if(this.marks>100)         {             this.marks=100;   ...

Sort Rows - Alphabets & Integer Matrix DC [30/05/2021]

Sort Rows - Alphabets & Integer Matrix  Code In C: #include <stdio.h> #include<stdlib.h> int main() {    int R,C;    scanf("%d %d\n",&R,&C);    char mat[R][C][101],arr[R],temp[R];    for(int i=0;i<R;i++)    {        for(int j=0;j<C;j++)        {        scanf("%s ",&mat[i][j]);        if(mat[i][j][0]>='a' && mat[i][j][0]<='z')        {            arr[i]=mat[i][j][0];            temp[i]=arr[i];        }    }    }    for (int i=0;i<R-1;i++){    for(int j=i+1;j<R;j++) {     if(temp[i]>temp[j])     {         char t=temp[i];         temp[i]=temp[j];         temp[j]=t;     } } } ...

DC [29/05/2021]

  IMPORTANT: Do not write the main() function as it is already defined. Example Input/Output 1: Input: 09:15 17:30 60 Output: 10:15 11:15 12:15 13:15 14:15 15:15 16:15 17:15 Explanation: Here X=60, so the alarm sounds every 60 minutes from 09:15 to 17:30. 10:15 11:15 12:15 13:15 14:15 15:15 16:15 17:15 Example Input/Output 2: Input: 04:00 12:15 45 Output: 04:45 05:30 06:15 07:00 07:45 08:30 09:15 10:00 10:45 11:30 12:15 ************************************************** CODING SNIPPET: void printAlarmTimings(char startTime[],char endTime[],int x) {     int startMM=atoi(&startTime[3]),endMM=atoi(&endTime[3]);     startTime[2]='\0';     endTime[2]='\0';     int startHH=atoi(startTime),endHH=atoi(endTime);     int startTimeInMins=(startHH*60)+startMM;     int endTimeInMins=(endHH*60)+endMM;     //     startTimeInMins+=x;     while(startTimeInMins<=endTimeInMins)     {   ...

DC [28/05/2021]

MATRIX - Remove Apples & Oranges Boundary Condition(s): 2 <= R, C <= 50 1 <= T <= R Input Format: The first line contains R and C separated by a space. The next R lines, each contains C characters separated by a space. The (R+2)nd line contains T. Output Format: The first R lines, each contains C characters separated by a space. Example Input/Output 1: Input: 5 6 A O O A O O O A O A A A A A O A A O O A O O A O O A A A O A 3 Output: * * * * * * A * * * * * O O O * O O A A O A A A O A O A A O Explanation: T = 1 (4 apples and 2 oranges in the last row). After removing the apples, the matrix becomes A * * * O * O O O A A O A A O A A A O A O A A O O A O O O O T = 2 (1 apple and 5 oranges in the last row). After removing the oranges, the matrix becomes * * * * * * A O * * O * O A O A A O A A O A A A O A O A A O T = 3 (3 apples and 3 oranges in the last row). After removing the apples, the matrix becomes * * * * * * A * * * * * O O O * O O A A O A A A O A O A A O Example Input...

DC [27/05/2021]

 FUNCTION CUSTOMTOUPPER: Note: The fromChar always occurs before the toChar in the English alphabet set. IMPORTANT: Do not write the main() function as it is already defined. Example Input/Output 1: Input: SkillRack h p Output: Modified String: SKILLRacK Explanation: In the given string S, the lower case alphabets that occur from h to p are k, i, l, l and k. After converting the above lower case alphabets to upper case, the string becomes SKILLRacK. Example Input/Output 2: Input: MicTesting#One#Two#Three a m Output: Modified String: MICTEstInG#OnE#Two#THrEE **************************************** CODE SNIPPET: void customToUpper(char str[], char fromChar, char toChar) { for(int i=0;i<strlen(str);i++) {     if(str[i]>=fromChar && str[i]<=toChar)     {         str[i]=toupper(str[i]);     } } } ****************************************

DC [26/05/2021]

IMPORTANT: Do not write the main() function as it is already defined. Example Input/Output 1: Input: 5 4 98 62 65 28 37 47 14 89 19 66 48 43 84 16 75 35 62 88 77 94 3 Output: Column 3: 65 14 48 75 77 Explanation: Here K = 3, the integers in the 3rd column are 65, 14, 48, 75 and 77. Hence the output is Column 3: 65 14 48 75 77 Function Get Column Example Input/Output 2: Input: 4 7 87 51 76 54 16 32 63 51 86 57 48 91 32 93 44 32 69 22 38 49 94 63 40 23 70 88 13 87 2 Output: Column 2: 51 86 32 40 SOLUTION: boundedArray* getColumn(int R, int C, int matrix[][C], int K) {int output[1001],l=0; for(int i=0;i<R;i++) {     output[l++]=matrix[i][K-1]; //IN THIS LINE PUT CAPITAL K } boundedArray bArr,*ptr=&bArr; bArr.SIZE=l; bArr.arr=output; return ptr; }

DC [25/05/2021]

Example Input/Output 1: Input: 52 2 Output: 3 Explanation: The binary representation of 52 is B = 110100. All prefixes in B and the corresponding decimal equivalents are given below. 110100 -> 52 11010 -> 26 1101 -> 13 110 -> 6 11 -> 3 1 -> 1 Here 52, 26 and 6 are divisible by 2. So the count 3 is printed as the output. Example Input/Output 2: Input: 147 3 Output: 4 Example Input/Output 3: Input: 98 6 Output: 3 Program in c: #include <stdio.h> #include <stdlib.h> #include <math.h> int main() {     int n,x;     scanf("%d %d",&n,&x);     int binary[64],l=0;     while(n!=0)     {         binary[l++]=n%2;         n/=2;     }     int count=0;     for(int i=0;i<l;i++)     {         int currdecimal=0,power=0;         for(int j=i;j<l;j++,power++)         { ...

DC Challenge[24/05/2021]

Function customCompare Example input/Output 1: AbcdEFghi jklAmnEopF Output: 1 Solution: #include<string.h> int customCompare(char str1[],char str2[]){     char upper1[101],upper2[101];     int ind1=0,ind2=0;     for(int index=0;index<strlen(str1);index++)     {         if(isupper(str1[index]))             upper1[ind1++]=str1[index];     }     upper1[ind1]='\0';     for(int index=0;index<strlen(str2);index++){         if(isupper(str2[index]))             upper2[ind2++]=str2[index];     }     upper2[ind2]='\0';     return strcmp(upper1,upper2)==0; }

DC May 23

DEFINE CLASS STICK: class Stick:     def __init__(self,value):         self.value=value     def __add__(value1,value2):         str1="Length: "+str(value1.value+value2.value)         return (str1) In the Second and Fourth Line, Double underscores are there don't put single Underscore If You have any errors put in Comments.

DC [22/05/2021]

FUNCTION GETUNITDIGITS char* getUniqueUnitDigits(int SIZE, int arr[]) {int freq[10]={0}; for(int i=0;i<SIZE;i++) {     freq[arr[i]%10]++; } char *str=malloc(sizeof(char)*10); int len=0; for(int i=9;i>=0;i--) {     if(freq[i]>0)     {         str[len++]=i+'0';     } } return str; } 

DC [21/05/2021]

  C Program #include<stdio.h> #include<stdlib.h> #include<string.h> int main() {int arr[1001]; char str[10001],ch; int len=0,flag=0; while(scanf("%[^\n]\n",&str)==1) {     char *token=strtok(str," ");     int cnt=0;     while(token!=NULL)     {         arr[len]=atoi(token);len++;         cnt++;         token=strtok(NULL," ");     }     if(cnt>1)flag=1; } if(flag==1) {     ch='\n'; } else{     ch=' '; } for(int i=len-1;i>=0;i--) {     printf("%d%c",arr[i],ch); } }

DC [20/05/2021]

  boundedArray* getArrayFromMatrix(int R,int C,int matrix[][C])     {         int arr[10001],len=0;         for(int i=R-1;i>=0;i--)         {             for(int j=C-1;j>=0;j--)             {             arr[len++]=matrix[i][j];             }         }      boundedArray bArr,*ptr=&bArr;      bArr.SIZE=len;      bArr.arr=arr;     return ptr; }

Skill Challenges[17/05/2021]

 #include <stdio.h> int main() {     int n;     scanf("%d\n",&n);     for(int ctr=1;ctr<=n;ctr++)     {         int sum=0,len=0,num;         char ch;         while(1)         {             scanf("%d%c",&num,&ch);             sum+=num;             len++;             if(ch=='\n' || ch=='\r'){                 break;             }         }         printf("%d %d\n",len,sum);     } }

skill Challenge [16/05/2021]

 r,c=map(int,input().split()) matrix=[list(map(int,input().split()))for i in range(r)] x,y=map(int,input().split()) print(*[i*j for i,j in zip(matrix[x-1],matrix[y-1][::-1])]) **************************************************

C--Starter-part007---skillrack

   EI - Print Pass or Fail ID:5523 #include<stdio.h> int main() {     int marks;     scanf("%d",&marks);     if(marks >= 35)     {         printf("pass");     }     else     {         printf("fail");     }     return 0; } EI - Print 1 to N ID:5553 #include <stdio.h> int main() {     int N;     scanf("%d", &N);     for(int ctr=1; ctr<=N; ctr++)     {         printf("%d ",ctr);     }     return 0; } EI - Print 1 to 10 (Id-5552) #include <stdio.h> int main() {     int ctr;     for(ctr=1; ctr<=10; ctr++)     {         printf("%d ",ctr);     }     return 0; }  EI - Check On or Off (Id-5544) #include<stdio.h> int main() {     int N;     scanf(...

Skill Challenge[13/05/2021]

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed. Often, programmers fall in love with Python because of the increased productivity it provides. Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault. Instead, wh...

C - Topic wise Practice Tracks ----->C - Logical Operators, Switch and Nested If Else Practice Programs----->PART001 - Challenges

  C - Logical Operators, Switch and Nested If Else - PART001 - Challenges Vegetable Shop ID:6638 #include<stdio.h> #include<stdlib.h> int main() {     int a,b,c,d,x;     scanf("%d %d %d %d%d",&a,&b,&c,&d,&x);     int a1=a*1+b*2+c*5+d*10;     if(x==a1){         printf("Paid");}     else if(a1<x){         printf("Not Paid %d",a1);     }     else{         printf("Paid %d",a1-x);     } }

SkillRack Daily Challenge[12/05/2021]

 #include<stdio.h> #include<stdlib.h> typedef struct Boundedarray{ int SIZE; int *arr; }boundedArray; boundedArray* getThreeOfFourDigits(int SIZE,int arr[]) { boundedArray *array=malloc(sizeof(boundedArray)); array->arr=malloc(sizeof(int)*SIZE); int ai=0,f=1; for(int i=0;i<SIZE;i++){ if(arr[i]>99 && arr[i]<10000){ array->arr[ai++]=arr[i]; f=0; } } array->SIZE=ai; if(f==1){ array->arr[0]=-1; array->SIZE=1; } return array; } int main() { int N; scanf("%d",&N); int arr[N]; for(int index=0;index<N;index++){ scanf("%d",&arr[index]); } boundedArray *bArr=getThreeOrFourDigit(N,arr); printf("Old Array:"); for(int index=0;index<N;index++){ printf("%d",arr[index]); } printf("\nNew Array:"); for(int index=0;index<bArr->SIZE;index++) { printf("%d ",bArr->arr[index]); } return 0; }

C - INTRO - PART005

 ID:6203 Print the String S #include<stdio.h> #include<stdlib.h> int main() {     char a[100];     scanf("%s",&a);     printf("%s",a); }

C - STARTER - PART001

 ID:5418 C - WU - Add Two Integers (Format Specifier) #include <stdio.h> int main() {     int A, B; scanf("%d %d",&A, &B);     printf("%d", A+B); }

C - INTRO - PART003

   ID:6133  Print A to B(Using While Loop) #include<stdio.h> #include<stdlib.h> int main() {     int A,B;     scanf("%d%d ",&A,&B);     while(A<B+1){         printf("% d",A);         A++;     } }

C - INTRO - PART002

    ID:6096  Check If Two Integers are Equal (Using if-else) #include<stdio.h> #include<stdlib.h> int main() {     int X,Y;     scanf("%d%d ",&X,&Y);     int m=(X==Y)?printf("Equal"):printf("Not Equal");     return 0; }

C - INTRO - PART001

    ID:6078  Count of Ice-cream(s) #include<stdio.h> #include<stdlib.h> int main() {     int a,b,c;     scanf("%d%d%d ",&a,&b,&c);     printf("%d",a+b+c); } ID:6079  Solve Equation with Four Integers #include<stdio.h> #include<stdlib.h> int main() {     int a,b,c,d;     scanf("%d%d%d%d ",&a,&b,&c,&d);     printf("%d",b*c-(a+d)); } ID:6080  Count of Cheetahs in the Zoo #include<stdio.h> #include<stdlib.h> int main() {     int a,b;     scanf("%d%d ",&a,&b);     printf("%d",a-b); } ID:6081  Product of Three Integers #include<stdio.h> int main() {int a,b,c; scanf("%d%d%d ",&a,&b,&c); printf("%d",a*b*c); } ID:6083  Cost of X chocolates #include<stdio.h> #include<stdlib.h> int main() {  int a,b;  scanf("%d%d",&a,&b);  printf("%d",a*b); } ID:6...

Python - VERY-EASY - PART004

Reverse Order - Print N to 1  a=int(input()) for i in range(a,0,-1):     print(i,end=" ")

C - INTRO - PART004

 ID:6110 Print 1 to N (Using for Loop) #include<stdio.h> #include<stdlib.h> int main() {     int a;     scanf("%d",&a);     for(int i=1;i<a+1;i++){         printf("% d",i);     } }