To the Top
File:  root - text - article - 2020 - 01 - string-compression.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 279 Views, 19809 Search Bots | 87 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Twitter:

Given an array of characters with repeats, compress it in place. The length after compression should be less than or equal to the original array.

Example:
Input: ['a', 'a', 'b', 'c', 'c', 'c']
Output: ['a', '2', 'b', 'c', '3']
Here's a starting point:


class Solution(object):
def compress(self, chars):
# Fill this in.

print Solution().compress(['a', 'a', 'b', 'c', 'c', 'c'])
# ['a', '2', 'b', 'c', '3']
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 279 Views, 19809 Search Bots | 87 Words Subscribe to Feed Burner

Related Articles

  1. Design Tic-Tac-Toe
  2. Making a Height Balanced Binary Search Tree
  3. Patterns for breaking down questions you haven
  4. Daily Interview Problem: 3 Sum
  5. Daily Interview Problem: Min Range Needed to Sort
  6. Algorithm Interview: Level Order Traversal of Binary Tree
  7. Skip the readings, focus on problems. And use all the hints!
  8. Daily Interview Problem: Spiral Traversal of Grid
  9. Algorithm Interview: Convert Roman Numerals to Decimal
  10. Daily Interview Question: Longest Sequence with Two Unique Numbers

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">