Posts

Define Class Event

Define Class Event Example Input/Output 1: Input: 5 TreasureHunt 200 60 ProjectExpo 500 180 RapidFireQuiz 200 20 PaperPresentation 400 120 Hackathon 500 180 Output: RapidFireQuiz 200 20 TreasureHunt 200 60 PaperPresentation 400 120 Hackathon 500 180 ProjectExpo 500 180 Exaplanation: Here N = 5. After sorting the events based on the given conditions, the events become RapidFireQuiz 200 20 TreasureHunt 200 60 PaperPresentation 400 120 Hackathon 500 180 ProjectExpo 500 180 Example Input/Output 2: Input: 6 ProjectExpo 800 180 TreasureHunt 100 90 Hackathon 800 240 TechQuiz 100 30 HexCoding 800 180 PaperPresentation 800 180 Output: TechQuiz 100 30 TreasureHunt 100 90 HexCoding 800 180 PaperPresentation 800 180 ProjectExpo 800 180 Hackathon 800 240 CODE SNIPPET:  class Event implements Comparable<Event> {     private String title="";     private int registrationFee,duration;     public Event(String title,int registration,int duration)     { ...

alphabet matrix minimum sum path

 PYTHON PROGRAM      r,c = map(int,input().split()) l = [input().lower().split()for i in range(r)] xs,ys = map(lambda x:int(x)-1,input().split()) xe,ye = map(lambda x:int(x)-1,input().split()) vh = [];hv=[];i,j = xs,ys while(i!=xe):     vh.append(ord(l[i][j])-ord('a')+1)     i+=1 if(i<xe)else -1 while(j!=ye):     vh.append(ord(l[i][j])-ord('a')+1)     j+=1 if(j<ye)else -1 vh.append(ord(l[i][j])-ord('a')+1) i,j=xs,ys while(j!=ye):     hv.append(ord(l[i][j])-ord('a')+1)     j+=1 if(j<ye)else -1 while(i!=xe):     hv.append(ord(l[i][j])-ord('a')+1)     i+=1 if(i<xe)else -1 hv.append(ord(l[i][j])-ord('a')+1) vh = sum(vh);hv = sum(hv);print(min([vh,hv]))

Function Calculate Distance DC[02/05/2021]

Function Calculate Distance typedef struct point {     int X;     int Y; } Point; IMPORTANT: Do not write the main() function as it is already defined. Example Input/Output 1: Input: 4 5 7 6 Output: 3.16 Explanation: The first point is (4, 5). The second point is (7, 6). The distance between the given two points is 3.16 (The distance is printed with the precision up to 2 decimal places). Example Input/Output 2: Input: 9 -2 0 0 Output: 9.22  CODE SNIPPET: double calculateDistance(Point *point1,Point *point2) { int x1=point1->X; int x2=point2->X; int y1=point1->Y; int y2=point2->Y; return sqrt(pow((x2-x1),2)+pow((y2-y1),2)); }

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)     {   ...