r/dailyprogrammer • u/nint22 1 2 • Jun 10 '13
[Easy] Longest Two-Character Sub-String
(Easy): Longest Two-Character Sub-String
This programming challenge is a classic interview question for software engineers: given a string, find the longest sub-string that contains, at most, two characters.
Author: /u/Regul
Formal Inputs & Outputs
Input Description
Through standard console input, you will be given a string to search, which only contains lower-case alphabet letters.
Output Description
Simply print the longest sub-string of the given string that contains, at most, two unique characters. If you find multiple sub-strings that match the description, print the last sub-string (furthest to the right).
Sample Inputs & Outputs
Sample Inputs
abbccc
abcabcabcabccc
qwertyytrewqSample Outputs
bbccc
bccc
tyyt
View all comments
Show parent comment
34
u/ReginaldIII Jun 10 '13
I've been teaching programming to people from all manner of disciplines for a few years now so here is the advice I give all of them.
The moral of the story is just that you need to pick a language that does what your task needs it to do. For this task out of PHP or Python I would say python is the better choice. Yes you could do this problem in PHP but why would you?