• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Compacting a set of number ranges

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would you compact a set of number ranges in pairs such that

eg. Given:[1,10], [2,5], [25, 40]
output : [1,10] covers [2,5] hence output would be [1,10] and [25,40]
 
Sheriff
Posts: 28401
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First I would put them in order, then I would merge adjacent pairs which overlapped.
 
C Halbe
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What type of collection/data structure would you use?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

C Halbe wrote:What type of collection/data structure would you use?



For what part? What have you tried and what specific problems are you having?

Start by spelling out clearly and in detail how you would do it "manually." Make sure that each step is very small, simple, and basic.
 
Paul Clapham
Sheriff
Posts: 28401
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

C Halbe wrote:What type of collection/data structure would you use?



That should be obvious. The choice is List, Set, Map. We want things in order so Set is out. We don't have keys and values so Map is out. That leaves List.

But as Jeff suggests, you should figure out what you want to do before you start deciding how to do it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic