Coder Social home page Coder Social logo

akhilkanike's Projects

guide icon guide

A collection of easy-to-understand guides to programming tools

narencandy icon narencandy

Naren is peculiar about color of candies Little Naren is very peculiar about colors. On his birthday, his mom wanted to buy candies for eating. So she asked him about his color preferences. The sophisticated little person that Naren is, he likes only two colors — amber and brass. His mom bought n candies, each of which was either amber or brass in color. You are provided this information in a string s consisting of characters 'a' and 'b' only, where 'a' denotes that the candy is amber, where 'b' denotes it being brass colored. When Naren saw the candies, he was furious with anger as he wanted all the balloons of the same color. In his anger, he painted some of the candies with the opposite color (i.e., he painted some amber ones brass and vice versa) to make all candies appear to be the same color. As he was very angry, it took him a lot of time to do this, but you can probably show him the right way of doing so, thereby teaching him a lesson to remain calm in difficult situations, by finding out the minimum number of candies needed to be painted in order to make all of them the same color. Input • The first line of input contains a single integer T, denoting the number of test cases. • The first and only line of each test case contains a string s. Output • For each test case, output a single line containing an integer — the minimum number of flips required. Example Input: 3 ab bb baaba Output: 1 0 2 Explanation In the first example, you can change amber to brass or brass to amber. In both the cases, both the candies will have same colors. So, you will need to paint 1 candy. So the answer is 1. In the second example, As the color of all the balloons is already the same, you don't need to paint any of them. So, the answer is 0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.