BigTiannn / Practice

0 stars 0 forks source link

Oyster's Warm Up Practice #1 #1

Open oysterkwok opened 9 years ago

oysterkwok commented 9 years ago

Given an array of integer arr (may include duplicate numbers and negative integers) Then given a legal query string query specifying some ranges (see example) Return all numbers in arr satisfying query query in ascending order.

Query Rules:

  1. Single number: 2 means only 2, as [2, 2]
  2. Range: -1~3 means query range from -1 to 3, as [-1, 3), which inclusive on left and exclusive on right // see Example 2
  3. ^ means and, v means or, and would be operate in prior to or
  4. Query string may be a very long string, and could contains overlapping ranges.
  5. All numbers in in query are within range of int
Example 1: 
arr = [-1, 0, 0, 2]
query = "-1~3" // query range from -1 to 3
result = [-1, 0, 0, 2]
Example 2: 
arr = [-1, 0, 0, 2]
query = "-1~0v2" // query range from -1 to 0 or 2
result = [-1, 2]
Example 3: 
arr = [2, 0, -1, 0]
query = "0~2^-1~1v2"
result = [0, 0, 2]
oysterkwok commented 9 years ago

@BigTiannn Take your time and try to solve it. Let me know if you got any confusion.