problem link:- TRAINSET Problem - CodeChef
please help
For each string, keep a count of how many times it occurs as 1 and how many times it appears as 0. Then take the sum of maximum over all strings in the answer.
You can use a simple hash-table like map and get the answer, doesn’t require much of a tweak.
maybe something like
map < string,pair<int,int> > frequency
key has two values i.e. frequency of (0,1). while iterating always take the maximum among both and add to your answer.
what is a map ?
can you tell me what is map as i don’t have CS background ?
I have not heard of it earlier .
Refer this.
Ok thanks a lot
is there any other way since I know only C language and in C language map function is not available ?
Learn another language
Ok
there’s always a way !
make and array of structures (having two elements string si and integer wi), scan all the elements for each i
, now apply qsort()
and sort them, now run a loop and check for equal elements, and update the result accordingly.
what if I do all these thing but without creating array of structures ?
then will it give TLE ?
Why using structure will reduce the time ?
It is no where reducing time, using structures helps you store two values at a time. also further sorting take O(NlogN), thus optimising it from O(N^2).