601. Delete Consecutive Same Words

EasyStackStackString

Given a list of words, repeatedly remove two adjacent equal words until no such pair remains, and return the resulting list. The input is JSON {words}.

Input: JSON {words}.

Output: Array — the remaining words in order.

Examples

Example 1
Input: {"words":["ab","ab","cd","ef"]}
Output: ["cd","ef"]
Explanation: The two 'ab' cancel.
Example 2
Input: {"words":["a","a","a"]}
Output: ["a"]
Explanation: One pair cancels, leaving one.
Example 3
Input: {"words":["x"]}
Output: ["x"]
Explanation: Nothing to remove.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →