Problem

Conditions

  1. has to be done in place ( space-constrained, ie. cannot allocate a new array)
  2. the order of non-zero elements on the right do not matter

Example

Input : arr[] = {0, 1, 2, 5, 0, 3, 0, 3};
Output : arr[] = {0, 0, 0, 2, 1, 3, 3, 5};

Solution

Python

Solve move all zeros to the left of the array in Python

Golang

Solve move all zeros to the left of the array in Golang

Takeaways

Find Tokenized Words in a String

Problem

What are Tokenized Words?

  1. Words without space. For example, abc, def, a, b, c
  2. Quoted words with or without space. For example, “qwerty asd zxcv”, “abc”, “a”

Example 01

  • Input: asd def qwe “qwerty asd zxcv” asf “tyuip dfhgdj fgh”
  • Output: [‘asd’, ‘def’, ‘qwe’, ‘“qwerty asd zxcv”’, ‘asf’…

https://www.basf.com/sg/en/media/news-releases/asia-pacific/2021/01/basf_caregen_supply_agreement.html

Leonard Yeo

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store