| about | help | code help+videos | done | prefs |
Given an array of numbers it might be possible to compress it by looking for repeating numbers in the sequence. data[] = {1,1,1,2,2,3,3}can be compressed intodata[] = {1,3,2,2,3,2}which uses one fewer elements.And the array data[] = {1,1,1,2,2,3}can be compressed intodata[] = {1,3,2,2,3,1}but since it isn't any smaller it should be left alone!Either return the compressed array if it is smaller than the original but otherwise just return the orginal compress([1, 1, 1, 2, 2, 3, 3]) → [1, 3, 2, 2, 3, 2] compress([1, 3, 2, 2, 3, 1]) → [1, 3, 2, 2, 3, 1] compress([1, 2, 3, 1, 2, 3, 1, 2, 3]) → [1, 2, 3, 1, 2, 3, 1, 2, 3] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 299
Copyright Nick Parlante 2017 - privacy