Skip to content

Commit

Permalink
Added Remove Colored Pieces if Both Neighbors are the Same Color
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace-Krypton committed Oct 2, 2023
1 parent d600601 commit 747622f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1239,4 +1239,15 @@ add_executable(Dota2Senate
target_link_libraries(
Dota2Senate
GTest::gtest_main
)

# Remove Colored Pieces if Both Neighbors are the Same Color
add_executable(RemoveColoredPiecesIfBothNeighborsAreTheSameColor
Medium/RemoveColoredPiecesIfBothNeighborsAreTheSameColor/include/solution.hpp
Medium/RemoveColoredPiecesIfBothNeighborsAreTheSameColor/tests/test.cpp
)

target_link_libraries(
RemoveColoredPiecesIfBothNeighborsAreTheSameColor
GTest::gtest_main
)
2 changes: 1 addition & 1 deletion Medium/ProductOfArrayExceptSelf/include/solution.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <vector>
#include <iostream>
#include <ranges>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <gtest/gtest.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <vector>
#include <iostream>
#include <algorithm>
#include <gtest/gtest.h>

class Solution {
public:
static auto winner_of_game(const std::string &colors) -> bool {
int32_t bob = 0;
int32_t alice = 0;

for (size_t i = 1; i < colors.size() - 1; ++i) {
if (colors[i - 1] == colors[i]
&& colors[i] == colors[i + 1]) {
if(colors[i] == 'A') ++alice;
if(colors[i] == 'B') ++bob;
}
}

return (alice >= (bob + 1));
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "../include/solution.hpp"

class RemoveColoredPiecesIfBothNeighborsAreTheSameColor : public ::testing::Test {
protected:
~RemoveColoredPiecesIfBothNeighborsAreTheSameColor() override = default;
};

TEST_F(RemoveColoredPiecesIfBothNeighborsAreTheSameColor, FirstTest) {
std::string colors = "AAABABB";

bool result = Solution::winner_of_game(colors);
bool expected = true;

ASSERT_EQ(result, expected);
}

TEST_F(RemoveColoredPiecesIfBothNeighborsAreTheSameColor, SecondTest) {
std::string colors = "AA";

bool result = Solution::winner_of_game(colors);
bool expected = false;

ASSERT_EQ(result, expected);
}

TEST_F(RemoveColoredPiecesIfBothNeighborsAreTheSameColor, ThirdTest) {
std::string colors = "ABBBBBBBAAA";

bool result = Solution::winner_of_game(colors);
bool expected = false;

ASSERT_EQ(result, expected);
}

auto main(int argc, char **argv) -> int {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 747622f

Please sign in to comment.