ROBOGAME - Solution help

Can I know where’s my mistake? I think I’ve the same input and output with the example. This is my code https://www.codechef.com/viewsolution/21338811

#include
//#include
#include
//#include
#include
#include

int inputNum;
std::vector<std::array> numberPosition;

bool check(std::string input){
		for(int i = 0; i < input.length(); i++){
			if(std::isdigit(input[i])){
				int index = input[i] - '0';
				//std::cout<<typeid(index).name()<<" "<<index<<std::endl;
				numberPosition.push_back({index, i});
			}
		}
		int min;
		int max = -10;
		for(auto numberMap: numberPosition){
			//std::cout<<max<<"|"<<numberMap[1]-numberMap[0]<= numberMap[1]-numberMap[0]){
				return false;
			}
			min = numberMap[1]-numberMap[0];
			max = numberMap[1]+numberMap[0];
			//std::cout<<max<<" | "<<min<>inputNum;
	while(inputNum--){
		std::string input;
		std::cin>>input;
		std::string res = (check(input))?"safe":"unsafe";
		std::cout<<res<<std::endl;
	}
}

@andraantariksa

Consider the case

…0

Answer with your solution : unsafe

Correct solution : safe

The problem with your approach is initial value of max i.e., -10

As in above case when 0 was at index 12 (indexing starting from 0) then,

numberMap[1]-numberMap[0] = -12

now max would be greater than -12 hence it would give wrong answer.

1 Like
//