Asked • 06/19/19

Display 1,2,3,4,5,6,8,10,11 as 1-6,8,10-11?

> I have this sequence **1,2,3,4,5,6,8,10,11** > > Expected output is **1-6,8,10-11** This problem is about formatting the sequence in easy readable form I tried with c# and used many if & else. Interviewer said, there is some simple algorithm to do this. I have no idea how to achive this very simple. > Also for 1,2,3 i shown 1-3. They said its wrong!. Is there any design pattern(interpreter) involved in this logic?

1 Expert Answer


Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.