Medium Data Structures > Orthogonal Range Search

**Maruf**, **Tawsif**, **Jubair** and I (**Feroz**) are four close friends. We have lots of similarities. We are studying at IIT (DU) and we are very interested in programming. Well, one more interesting fact is we all love to play hide and seek game. There are **N** rooms in a line in IIT and each room is favourite to exactly one of us. While playing game each of us hide ourselves in one of his favourite rooms. To have much fun we try to be as close as possible. Can you answer what's the minimum range of rooms that we can hide ourselves? Input: ------ Input starts with an integer **T (1<=20)**, denoting the number of test cases. Each case contains an integer **N (4 ≤ N ≤ 100000)** denoting the number of rooms. The next line will contain **N** characters denoting which of us like this room. Each of these characters will be one of first letters of our names. It is guaranteed solution always exists. Output: ------- For each case of input, output the minimum length of the room range that we can hide ourselves. Sample Input ------------ 2 7 TMFMFJJ 5 FMTJM Sample Output ------------- 6 4

Feroz Ahmmed

Language |
Time Limit (seconds) |

C | 1.00 |

C++ | 1.00 |

C++14 | 1.00 |

C# | 1.00 |

Go | 1.00 |

Java | 1.00 |

JavaScript | 1.00 |

Objective-C | 1.00 |

Perl | 1.00 |

PHP | 1.00 |

Python | 1.00 |

Python3 | 1.00 |

Ruby | 1.00 |

VB.Net | 1.00 |

Solve/Submission

# | User | Language | Timing |
---|---|---|---|

01 | seyedssz | Cpp14 | 0.00s |

02 | shakil2021 | Cpp | 0.00s |

03 | int_elligent | Cpp | 0.00s |

04 | Frdhsn | Cpp | 0.00s |

05 | Meheraj_Hossain | Cpp14 | 0.00s |

06 | twyu0721 | Cpp | 0.00s |

07 | Tarikul_Topu | Cpp14 | 0.00s |

08 | TarikulCSE | Cpp14 | 0.00s |

09 | Sarwar05 | Cpp | 0.00s |

10 | monir769 | Cpp14 | 0.01s |

11 | robin_aust | Cpp14 | 0.01s |

12 | sk23 | Cpp | 0.01s |

13 | feodorv | C | 0.01s |

14 | pulak_ict_mbstu | Cpp14 | 0.01s |

15 | Morass | Cpp14 | 0.01s |

16 | clkjwdhc | Cpp | 0.01s |

17 | anik_JU | Cpp | 0.01s |

18 | tariqiitju | Cpp14 | 0.01s |

19 | rayhan50001 | Cpp14 | 0.01s |

20 | mir003 | Cpp | 0.02s |

21 | ehsan_sshuvo96 | Cpp | 0.02s |

22 | devcoder | CSharp | 0.04s |

23 | sakib_muhit | Cpp14 | 0.04s |

24 | RandyWaterhouse | Python3 | 0.06s |

25 | Zeronfinity | Cpp14 | 0.07s |

26 | emrul | Cpp14 | 0.14s |

27 | mir_lutfur_rahman | Cpp14 | 0.15s |

28 | SakibAlamin | Cpp14 | 0.18s |

29 | PKP_007 | Cpp14 | 0.18s |

30 | Robbinb1993 | Cpp | 0.19s |

31 | nasif2587 | Cpp14 | 0.19s |

32 | MASUDUR_RAHMAN | Cpp14 | 0.24s |

33 | moinul_shaon | Cpp14 | 0.32s |

34 | prantacse14 | Cpp14 | 0.32s |

35 | mtmohim | Cpp14 | 0.34s |

36 | underSpirit | Cpp14 | 0.36s |

37 | mamun4122 | Cpp14 | 0.36s |

38 | dipta007 | Cpp14 | 0.37s |

39 | bishal_biswas | Cpp14 | 0.38s |

40 | abuasifkhan | Cpp14 | 0.39s |

41 | froghramar | Cpp14 | 0.40s |

42 | Skyfall009 | Cpp14 | 0.40s |

43 | mehadi_sust | Cpp14 | 0.41s |

44 | clcrr | Cpp14 | 0.46s |

45 | abid1 | Cpp14 | 0.47s |

46 | shuvo_iu | Cpp14 | 0.48s |

47 | Foyaz05 | Cpp14 | 0.48s |

48 | ahqmrf | Cpp14 | 0.48s |

49 | evan | Cpp14 | 0.48s |

50 | anowar1112 | Cpp14 | 0.49s |

Copyright © 2015-2016 Dev Skill.

Feedback
#### Your feedback is our precious!

## Thank you for providing feedback! Our developers will be happy :)

## Sorry there was a problem when submitting the feedback. Please try again. :(