Interview Question

Country: United States

Comment hidden because of low score. Click to expand.
of 0 vote

Of course there is a way to do it, with remembering 
the last char and current char and proceed, 
but that is not cool. That is too mundane.
So, I propose this insanely interesting strategy
def reduce_string( some_string ) {
  res = some_string
  for ( c : some_string ){
    regex_pattern = str("[%s]{2,}", c)
    res = res.replaceAll(regex_pattern,"")
println( reduce_string( "aaaaacbbbbxxxdddddefghhg") )

Well, well. I am not entirely sure... but this seems to fit the bill. It was fun.
Can anyone break it?

- NoOne April 27, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

//g++ 7.4.0

#include <bits/stdc++.h>
using namespace std;

int main()
string c;
cin >> c;
int k;
cin >> k;
stack<pair<char, int> > s;

int n = c.length();
for (int i=0; i<n; ++i) {

if (s.empty()) s.push(make_pair(c[i], 1));
else {
if ( == c[i] && == k-1) {
while (!s.empty() && == c[i]) s.pop();
} else if ( == c[i]) {
} else {
s.push(make_pair(c[i], 1));
int m = s.size();
char res[m];
for (int i=m-1; i>=0; --i) {
res[i] =; s.pop();
for (int i=0; i<m; ++i) {
cout << res[i];

return 0;

- hpclearn July 02, 2020 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More