Tough TCS Codevita: Zone 2

tried many ways and covered all the corner cases but still WA on private test cases. Dont know what else we had to do with it.

I have solved Election Problem and String pair was getting wrong answer.
can anyone who can help in string pair one

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++) 
#define all(v) v.begin(),v.end()
#define F first
#define S second
ll fun(string s)
{
   ll count=0;
   for(int i=0;i<(int)s.length();i++)
   {
   	if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')
   	{
   		count++;
   	}
   }
   return count;
}
void solve()
{
   int n;
   cin>>n;
   int arr[n];
   string s[]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen",
"fourteen","fifteen","sixteen","seventeen",	"eighteen",	"nineteen","twenty","twenty one","twenty two","twenty three","twenty four","twenty five",
"twenty six",
"twenty seven",
"twenty eight",
"twenty nine",
"thirty",
"thirty one",	
"thirty two",	
"thirty three",
"thirty four",
"thirty five",
"thirty six",	
"thirty seven",
"thirty eight",
"thirty nine",
"forty","forty one","forty two","forty three","forty four","forty five","forty six","forty seven","forty eight","forty nine","fifty","fifty one","fifty two",
"fifty three","fifty four","fifty five","fifty six","fifty seven","fifty eight","fifty nine","sixty","sixty one","sixty two","sixty three","sixty four","sixty five","sixty six","sixty seven",
"sixty eight","sixty nine","seventy","seventy one","seventy two","seventy three","seventy four","seventy five","seventy six","seventy seven","seventy eight","seventy nine",
"eighty","eighty one","eighty two","eighty three","eighty four","eighty five","eighty six","eighty seven","eighty eight","eighty nine","ninety","ninety one","ninety two","ninety three",
"ninety four","ninety five","ninety six","ninety seven","ninety eight","ninety nine","hundred"};
   for(int i=0;i<n;i++)
   {
   	cin>>arr[i];
   	//cout<<s[arr[i]]<<endl;
   }
   vector<ll> val;
   for(int i=0;i<n;i++)
   {
   	val.push_back(fun(s[arr[i]]));
   }
   ll sum=0;
   for(int i=0;i<(int)val.size();i++)
   {
   	sum+=val[i];
   }
   //sort(arr,arr+n);
   ll res=0;
   set<pair<ll,ll>> se;
   vector<bool> vis(n,false);
   for(int i=0;i<n;i++)
   {
   		for(int j=i+1;j<n;j++)
   		{
   		
   			if(!vis[i] && !vis[j] && arr[i]+arr[j]==sum)
   			{
   				res++;
   				vis[i]=true;
   				vis[j]=true;
   			}
   		}
   }
   if(res>100)
   {
   	cout<<"greater 100"<<endl;
   }
   else
   {
   	
   	cout<<s[res]<<endl;
   	
   }
   
}
int main()
{
//	ios_base::sync_with_stdio(false); 
 //  cin.tie(NULL);  
   int t;
   t=1;
   while(t--)
   {
   	solve();
   }
}
2 Likes

did any one solved that question. coz i got WA though i take care of “hundred”. Is there any corner case which i missed;

yeah bro, i gave around 2 hrs to that question but it didn’t pass private cases.

My friends tried to solve that question a lot. Nothing worked. This question (together with a lot of other questions) was a complete goo. They didn’t tell whether to print 21 has twenty one or twentyone or twenty-one. They didn’t clearly define what they mean by unordered pairs. In case of (2, 3) does (2, 2) also count? Do we have to make the unordered pairs on the indices of the given array or treat the elements of the given array as a set?
It was a complete mess.

I can bitch about a lot of their questions.

12 Likes

i wasted 1hr on this question, testcase were worng, i have also searched it on internet thier i find the only possible way to get the answer is when take minute in range[0,98) and it got accepted, such a senseless question.

1 Like

what the fk :frowning:

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