Tough TCS Codevita: Zone 2

Yes, you are right i was also confused about printing of answer and that’s why i submitted solution multiple times. I also remind a question which is about voting queue, that is also very confusing to me and almost took 2 hrs to solve.

Yes

I also coded almost same solution (logic) and I was also getting wrong answer!!!

When the result will announced??

TCS u have fkin idiot setters , @ashish_kaur u said that u mailed them abd they said test cases were correct , please mail that chutiya’s konsi duniya se minute ki range [0,98) hoti hai , and even in their test case they said 2235322 means minute range from 0 to 59 .

8 Likes

I think you got the tough set, I mean all these problems were hard. How many did you solve?

I just solved one :frowning:
TCS CodeVita 9 Zone 2
Fill the Cube Problem:

import java.util.*;

class Cube{
	// anti-clockwise direction 
    public void rotateMatrix( int N, int mat[][]) 
    { 
        // Consider all squares one by one 
        for (int x = 0; x < N / 2; x++) { 
            // Consider elements in group 
            // of 4 in current square 
            for (int y = x; y < N - x - 1; y++) { 
                // Store current cell in 
                // temp variable 
                int temp = mat[x][y]; 
                // Move values from right to top 
                mat[x][y] = mat[y][N - 1 - x]; 
                // Move values from bottom to right 
                mat[y][N - 1 - x] 
                    = mat[N - 1 - x][N - 1 - y]; 
                // Move values from left to bottom 
                mat[N - 1 - x][N - 1 - y] = mat[N - 1 - y][x]; 
                // Assign temp to left 
                mat[N - 1 - y][x] = temp; 
            } 
        }
    } 
    
    //For melting of matrix
    /* Melting is done by taking the first column
     * Then two variables top and down
     * top point to the first element of the first column
     * down points to the last element of the first column
     * top and down moves towards each other by iterating the elements in the first column from their position
     * if top founds a 'D' (ie) zero in our case, then it'll change it to -1 to denote space and move to next element
     * if top founds a 'C', top will get assigned to C and wait for down to find a 'D'
     * if down finds a 'D' iterating from the bottom , then down will change the 'D' to 'C' and top will change it's 'C' to space (ie) '-1'
     * and then top will continue to search for another C while continuously changing 'D' to space
     * Thus the first column will be melted and it'll be repeated for the remaining columns
     */
    public void melting(int N, int mat[][]) {
    
    	for(int i=0;i<N;i++) {
    		int top=0;
    	    int down=N-1;
    	  for(int loop=0;loop<N;loop++) {
    		  if(top>down) {
    			  break;
    		  }
    		for(;top<N;top++) {
    			if(mat[top][i]==0) {
    				mat[top][i]=-1; //To denote the space as -1 after C drops
    			}
    			else if(mat[top][i]==1) {
    			   break;
    			}
    		}
    		for(;down>0;down--) {
    			if(mat[down][i]==0) {
    				mat[down][i]=1; //changes down to 1 and top to -1 to make the matrix look melted
    				mat[top][i]=-1; //To denote the space as -1 after C drops
    				top++;
    				down--;
    				break;
    			}
    		}
    		
    	  }
    	}

    }
    
    
    /*For finding the square wall to be fit inside the melted matrix
     * We'll create a 1D array of size N which is the wall_size given as input 
     * Assign all the elements of array from 1 to the input N ex: arr[0]=1, arr[1] = 2 ......arr[N-1]=N
     * We'll use each element of the array as the square wall size to fit into our melted matrix
     * and assign -1 to the respective array[i] if it fits inside our matrix
     * Atlast we'll iterate our fully checked array from the last index arr[N] and if arr[i] matches -1 
     * then we'll return the correspinding array element position as the biggest square to be fitted to our matrix
     * To check if a square fits our matrix, we'll take the first column and iterate from top
     * We'll continue our iteration and count the no.of iterations of spaces in our first column
     * If we find a C instead of a space then we'll stop the iteration and check if no.of iteration == array[i]
     * If it satisfies then we'll increment a new variable called loop and check whether loop == array[i]
     * If it equals then we've successfully fitted a square and assign array[i]=-1 and move on the next element in our array
     * if not then we'll move on to next column till loop==array[i]
     * if no.of iterations < array[i] then we'll move to next column while setting loop back to 0 and check from first 
     * whether we can fit a square. If not we'll not assign -1 to our array.
     */
    public int wall_size(int N,int mat[][]){
    	
    	   int[] arr = new int[N];
    	    for(int i=0;i<N;i++) {
    	    	arr[i]=(i+1);
    	    }
    	    
    	    
    	    
    	    for(int i=0;i<arr.length;i++) {
    	    	int loop=0;
  
    	    	for(int col=0;col<N;col++) {
    	  	    	int count =0;
    	    		for(int row=0;row<N;row++ ) {
    	    			if(count==arr[i]) {
    	    				break;
    	    			}
    	    			if(mat[row][col]==-1) {
    	    			    count++;
    	    			    //For Debugging
    	    			    //System.out.println("column: "+col +"Row: "+row);
    	    			}
    	    			else  if(mat[row][col]==1)
    	    			{
    	    				//For Debugging
    	    				//System.out.println("same");	
    	    				break;
    	    			}
    	    		}
    	    	    if(count<arr[i]) {
    	    	    	//For Debugging
    	    	    	//System.out.println("COUNT:"+count);
    	    	    	loop=0;
    	    	    	
    	    	    }
    	    		if(count==arr[i]) {
    	    			loop++;
    	    			if(loop==arr[i]) {
    	    				//For Debugging
    	    				//System.out.printf("\n Array: %d , column: %d, loop: %d, count: %d \n",arr[i],col,loop,count);
    	    				arr[i]=-1;
    	    				
    	    				break;
    	    			
    	    			}
    	    		}
    	    		
    	    	
    	    	}
    	    }
    	    
    	    
    	    for(int i=(arr.length)-1;i>=0;i--) {
    	    	if(arr[i]==-1) {
    	    		return (i+1);
    	    	}
    	    }
    	    return 0;
    }
    
    //for debugging printing of the matrix 
    public void print(int size,int[][] mat) {
    	System.out.println();
    	for(int i =0;i<size;i++	) {
    		for ( int j=0;j<size;j++) {
    			System.out.print("  "+mat[i][j]+"  ");
    		}
    		System.out.println();
    	}
    }
  
}


//Main class
public class Cube_Fill {
 public static void main(String[] args) {
	 Scanner input = new Scanner(System.in);
	 int wall_size = input.nextInt();
	 input.nextLine();
	 String[] bricks = new String[wall_size];
	 int[][] bmatrix = new int[wall_size][wall_size];
	 int[][] bmatrix1 = new int[wall_size][wall_size];

	 
	 //For converting the input to matrix form C=1 and D=0
	 for(int i=0;i<bricks.length;i++) {
		 bricks[i] = input.nextLine();
		for(int j=0;j<bricks.length;j++) {
			if(bricks[i].charAt(j)=='C')
						bmatrix[i][j] = 1;
			else
				bmatrix[i][j]=0;
		}
	 }
	 
	 Cube cubObj = new Cube();
	 
	 int[][] k = new int[2][2];
	 k[0][1]=1;
	 int[][] j = new int[2][2];
	 
	 for(int i=0;i<k.length;i++) {
	 System.arraycopy(k[i]	, 0, j[i], 0, k[0].length);
	 }
	 j[0][1] = 0;
	 System.out.println(k[0][1]);
	 
	
	//Copying bmatrix for rotation and storing it in another bmatrix1
	for(int i=0;i<bmatrix.length;i++) {
	 System.arraycopy(bmatrix[i], 0, bmatrix1[i], 0, bmatrix[0].length);
	}
     cubObj.rotateMatrix(wall_size, bmatrix1);  //rotation happens
	 
     //cubObj.print(wall_size, bmatrix);  -- Print the matrix form of the input
			
	 //Melting 
	 cubObj.melting(wall_size, bmatrix);
	 cubObj.melting(wall_size,bmatrix1);
	 
	 //cubObj.print(wall_size, bmatrix);  -- Print the melted matrix
		
	 int notRotated =  cubObj.wall_size(wall_size, bmatrix); //Identifies the wall_size
	 int rotated = cubObj.wall_size(wall_size, bmatrix1);    //Identifies the wall_size of the rotated matrix
	 
	 //To check the wall_sizes and print the bigger one.
	 if(notRotated>=rotated) {
		 System.out.println(notRotated);
	 }
	 else {
		 System.out.println(rotated);
	 }

   }

}
2 Likes

Yes

None😔

1 Like

I had the same set.

2 Likes

Same also happened with me,my graph was not showing even after 15 minutes of an AC submission.Though my submission section was showing correctly.

was your approach correct and submitted successfully?

Anyone solved string pair problem and got ac ?if yes ,can plzz share the code

After giving today two competition codevita and google than i realize that service based company ask tough question rather than product base because in codevita round i have solved only one question in 6 hours but in google have 60 mins and give two problem and i have solve first and second one partially

2 Likes

Even Odd was not solvable bro :slightly_smiling_face:

They said they have tested thoroughly.
You know what thorough testing is like:

  • Tester: “Hey! Can you share the code that you used for testcase generation?”
  • Setter: “Ya Sure, here it is.”
  • Tester (in mind): “Yahi code submit karke bol deta hu testing ho gayi. Inko kya hi pata chalega.”

Tada, “thorough” testing completed! :clap: :clap: :clap: :clap:

Later when the contest is live:

TCS be like: “Hmm, this time we have made tough problems. Impressive!”

Aww Snap, did I write problems! Sorry, those are questions in TCS’s language :slightly_smiling_face:

7 Likes

i wasted a lot of hrs in this

Hello Passionate Coder, Let me tell you about a legend
TCS: Codevita
This was the the most shittiest S H I T I have ever experienced in my entire S H I T T Y life!
This is the tale of the biggest problem setting scandal in the whole world!

  • Head Guy: Guys, come on its only 45 mins to start the contest, we have to frame 25 problems!
  • TCS Intern: Don’t worry sir, I’ll make problems, test data and upload within a minute.
  • Samajdar Guy: Sir, I’ll do the testing.
  • Head Guy: Koi sense hai iss baat ki? Humko toh nahi lag rahi Why waste time in testing? You just make sure you reframe the questions to make it look difficult!

(While Editing)

  • Now Non-Samajdar Guy: Oh snap! We have so less time remaining. I don’t have enough time to read and reframe all the questions. What should I do?

He prays to god to help him, but apparently God was busy so he sent, SELMON BHOI to help him

  • SELMON: Hey Boi, don’t worry at all. Just delete every alternate sentence from the problem statement, it will become DIFFICULT
  • Non-Samajdar guy: Oh yeahh SELMON GOD, thanku so much!

This is how the whole contest was made, were everyone was on high weed!
(Actually it was not weed, it was some Grass from village grassland where people go every morning for shitting)
Thus the grass proved the law of conservation of shittiness

22 Likes

#include<bits/stdc++.h>

using namespace std;

string num[101]={“zero”,“one”,“two”,“three”,“four”,“five”,“six”,“seven”,“eight”,
“nine”,“ten”,“eleven”,“twelve”,“thirteen”,“fourteen”,“fifteen”,“sixteen”,“seventeen”,
“eighteen”,“nineteen”,“twenty”,“twentyone”,“twentytwo”,“twentythree”,“twentyfour”,
“twentyfive”,“twentysix”,“twentyseven”,“twentyeight”,“twentynine”,“thirty”,“thirtyone”,
“thirtytwo”,“thirtythree”,“thirtyfour”,“thirtyfive”,“thirtysix”,“thirtyseven”,
“thirtyeight”,“thirtynine”,“forty”,“fortyone”,“fortytwo”,“fortythree”,“fortyfour”,
“fortyfive”,“fortysix”,“fortyseven”,“fortyeight”,“fortynine”,“fifty”,“fiftyone”,“fiftytwo”,
“fiftythree”,“fiftyfour”,“fiftyfive”,“fiftysix”,“fiftyseven”,“fiftyeight”,“fiftynine”,
“sixty”,“sixtyone”,“sixtytwo”,“sixtythree”,“sixtyfour”,“sixtyfive”,“sixtysix”,“sixtyseven”,“sixtyeight”,“sixtynine”,“seventy”,
“seventyone”,“seventytwo”,“seventythree”,“seventyfour”,“seventyfive”,“seventysix”,“seventyseven”,“seventyeight”,“seventynine”,
“eighty”,“eightyone”,“eightytwo”,“eightythree”,“eightyfour”,“eightyfive”,“eightysix”,“eightyseven”,“eightyeight”,“eightynine”,
“ninety”,“ninetyone”,“ninetytwo”,“ninetythree”,“ninetyfour”,“ninetyfive”,“ninetysix”,“ninetyseven”,“ninetyeight”,“ninetynine”,“hundred”
};

int main(void) {

int i,n,sum=0,count=0,f[101],j,present[101];

cin>>n;

for(int i=1;i<101;i++) present[i]=0;

int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
present[a[i]]++;
}

f[1]=2,f[2]=1,f[3]=2,f[4]=2,f[5]=2,f[6]=1,f[7]=2,f[8]=2,f[9]=2,f[10]=1,f[11]=3,f[12]=2,f[13]=3,f[14]=4,f[15]=3,f[16]=3,f[17]=4,f[18]=4,f[19]=4,f[20]=1,f[21]=3,f[22]=2,f[23]=3,f[24]=3,f[25]=3,f[26]=2,f[27]=3,f[28]=3,f[29]=3,f[30]=1,f[31]=3,f[32]=2,f[33]=3,f[34]=3,f[35]=3,f[36]=2,f[37]=3,f[38]=3,f[39]=3,f[40]=1,f[41]=3,f[42]=2,f[43]=3,f[44]=3,f[45]=3,f[46]=2,f[47]=3,f[48]=3,f[49]=3,f[50]=1,f[51]=3,f[52]=2,f[53]=3,f[54]=3,f[55]=3,f[56]=2,f[57]=3,f[58]=3,f[59]=3,f[60]=1,f[61]=3,f[62]=2,f[63]=3,f[64]=3,f[65]=3,f[66]=2,f[67]=3,f[68]=3,f[69]=3,f[70]=2,f[71]=4,f[72]=3,f[73]=4,f[74]=4,f[75]=4,f[76]=3,f[77]=4,f[78]=4,f[79]=4,f[80]=2,f[81]=4,f[82]=3,f[83]=4,f[84]=4,f[85]=4,f[86]=3,f[87]=4,f[88]=4,f[89]=4,f[90]=2,f[91]=4,f[92]=3,f[93]=4,f[94]=4,f[95]=4,f[96]=3,f[97]=4,f[98]=4,f[99]=4,f[100]=2;

for(i=0;i<n;i++)sum+=f[a[i]];

for(i=1;i<101;i++)
{
for(j=i;j<101;j++)
{
if((i!=j)&((present[i]>0)&(present[j]>0))&(i+j==sum)) count++;
else if((i==j)&(present[i]>=2)&(i+j==sum)) count++;
}
}
//printf("%s",num[count-1]);
//printf(“count”)
if(cout<=100) cout<<num[count];
else cout<<“greater 100”;
return 0;
}

i think you have some small mistakes in ur code , this should be correct one.

1 Like

Nice, so that means. I had 2 unsolvable problems in my set. And was left with 4 which were hard🙂

3 Likes

We are same bro, I am able to do the B(Election) only :slight_smile: