# """# This is the ArrayReader's API interface.# You should not implement it, or speculate about its implementation# """# class ArrayReader(object):# # Compares 4 different elements in the array# # return 4 if the values of the 4 elements are the same (0 or 1).# # return 2 if three elements have a value equal to 0 and one element has value equal to 1 or vice versa.# # return 0 : if two element have a value equal to 0 and two elements have a value equal to 1.# def query(self, a: int, b: int, c: int, d: int) -> int:## # Returns the length of the array# def length(self) -> int:#classSolution:defguessMajority(self,reader:"ArrayReader")->int:n=reader.length()x=reader.query(0,1,2,3)a,b=1,0k=0foriinrange(4,n):ifreader.query(0,1,2,i)==x:a+=1else:b+=1k=iy=reader.query(0,1,2,4)ifreader.query(1,2,3,4)==y:a+=1else:b+=1k=0ifreader.query(0,2,3,4)==y:a+=1else:b+=1k=1ifreader.query(0,1,3,4)==y:a+=1else:b+=1k=2ifa==b:return-1return3ifa>belsek
/** * // This is the ArrayReader's API interface. * // You should not implement it, or speculate about its implementation * interface ArrayReader { * public: * // Compares 4 different elements in the array * // return 4 if the values of the 4 elements are the same (0 or 1). * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or * vice versa. * // return 0 : if two element have a value equal to 0 and two elements have a value equal * to 1. public int query(int a, int b, int c, int d); * * // Returns the length of the array * public int length(); * }; */classSolution{publicintguessMajority(ArrayReaderreader){intn=reader.length();intx=reader.query(0,1,2,3);inta=1,b=0;intk=0;for(inti=4;i<n;++i){if(reader.query(0,1,2,i)==x){++a;}else{++b;k=i;}}inty=reader.query(0,1,2,4);if(reader.query(1,2,3,4)==y){++a;}else{++b;k=0;}if(reader.query(0,2,3,4)==y){++a;}else{++b;k=1;}if(reader.query(0,1,3,4)==y){++a;}else{++b;k=2;}if(a==b){return-1;}returna>b?3:k;}}
/** * // This is the ArrayReader's API interface. * // You should not implement it, or speculate about its implementation * class ArrayReader { * public: * // Compares 4 different elements in the array * // return 4 if the values of the 4 elements are the same (0 or 1). * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or vice versa. * // return 0 : if two element have a value equal to 0 and two elements have a value equal to 1. * int query(int a, int b, int c, int d); * * // Returns the length of the array * int length(); * }; */classSolution{public:intguessMajority(ArrayReader&reader){intn=reader.length();intx=reader.query(0,1,2,3);inta=1,b=0;intk=0;for(inti=4;i<n;++i){if(reader.query(0,1,2,i)==x){++a;}else{++b;k=i;}}inty=reader.query(0,1,2,4);if(reader.query(1,2,3,4)==y){++a;}else{++b;k=0;}if(reader.query(0,2,3,4)==y){++a;}else{++b;k=1;}if(reader.query(0,1,3,4)==y){++a;}else{++b;k=2;}if(a==b){return-1;}returna>b?3:k;}};
/** * // This is the ArrayReader's API interface. * // You should not implement it, or speculate about its implementation * type ArrayReader struct { * } * // Compares 4 different elements in the array * // return 4 if the values of the 4 elements are the same (0 or 1). * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or vice versa. * // return 0 : if two element have a value equal to 0 and two elements have a value equal to 1. * func (this *ArrayReader) query(a, b, c, d int) int {} * * // Returns the length of the array * func (this *ArrayReader) length() int {} */funcguessMajority(reader*ArrayReader)int{n:=reader.length()x:=reader.query(0,1,2,3)a,b:=1,0k:=0fori:=4;i<n;i++{ifreader.query(0,1,2,i)==x{a++}else{b++k=i}}y:=reader.query(0,1,2,4)ifreader.query(1,2,3,4)==y{a++}else{b++k=0}ifreader.query(0,2,3,4)==y{a++}else{b++k=1}ifreader.query(0,1,3,4)==y{a++}else{b++k=2}ifa==b{return-1}ifa>b{return3}returnk}
/** * // This is the ArrayReader's API interface. * // You should not implement it, or speculate about its implementation * class ArrayReader { * // Compares 4 different elements in the array * // return 4 if the values of the 4 elements are the same (0 or 1). * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or vice versa. * // return 0 : if two element have a value equal to 0 and two elements have a value equal to 1. * query(a: number, b: number, c: number, d: number): number { }; * * // Returns the length of the array * length(): number { }; * }; */functionguessMajority(reader:ArrayReader):number{constn=reader.length();constx=reader.query(0,1,2,3);leta=1;letb=0;letk=0;for(leti=4;i<n;++i){if(reader.query(0,1,2,i)===x){++a;}else{++b;k=i;}}consty=reader.query(0,1,2,4);if(reader.query(1,2,3,4)===y){++a;}else{++b;k=0;}if(reader.query(0,2,3,4)===y){++a;}else{++b;k=1;}if(reader.query(0,1,3,4)===y){++a;}else{++b;k=2;}if(a===b){return-1;}returna>b?3:k;}