Skip to content

Commit

Permalink
Merge pull request #27 from amsharma44/string_reduction
Browse files Browse the repository at this point in the history
String reduction
  • Loading branch information
ows-ali authored Oct 17, 2018
2 parents 8838e18 + 6190b1f commit d1d240f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 57 deletions.
57 changes: 0 additions & 57 deletions angry-children-2.cs

This file was deleted.

50 changes: 50 additions & 0 deletions string-reduction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
class Solution {

static int stringReduction (string a) {
int[] ar = new int[3];
for(int i = 0; i < a.Length; i++)
{
if(a[i] == 'a')
{
ar[0]++;
}else if(a[i] == 'b')
{
ar[1]++;
}
else
{
ar[2]++;
}
}

if((ar[0] == 0 && ar[1] == 0) || (ar[1]== 0 && ar[2] == 0)||(ar[0] == 0 && ar[2] == 0))
{
return a.Length;
}

if ((ar[0] % 2 == 0 && ar[1] %2== 0) && (ar[1] %2 == 0 && ar[2] %2== 0))
{
return 2;
}

if ((ar[0] % 2 == 1 && ar[1] % 2 == 1) && (ar[1] % 2 == 1 && ar[2] % 2 == 1))
{
return 2;
}

return 1;
}

static void Main(String[] args) {
int res;
int _t_cases = Convert.ToInt32(Console.ReadLine());
for (int _t_i=0; _t_i<_t_cases; _t_i++) {
String _a = Console.ReadLine();
res=stringReduction(_a);
Console.WriteLine(res);
}
}
}

0 comments on commit d1d240f

Please sign in to comment.