design datum structure efficiently find majority element give subarraythe majority element subarray element occur threshold time subarrayimplemente MajorityChecker classmajoritycheckerint arr Initializes instance class give array arrint queryint leave int right int threshold return element subarray arrleftright occur threshold times 1 element exist Example 1inputmajoritychecker query query query1 1 2 2 1 1 0 5 4 0 3 3 2 3 2outputnull 1 1 2explanationmajoritychecker majoritychecker new MajorityChecker1 1 2 2 1 1majoritycheckerquery0 5 4 return 1majoritycheckerquery0 3 3 return 1majoritycheckerquery2 3 2 return 2 Constraints1 arrlength 2 1041 arri 2 1040 leave right arrlengththreshold right leave 12 threshold right leave 1At 104 call query