diff --git a/C++/Easy/ForLoop.cpp b/C++/Easy/ForLoop.cpp new file mode 100644 index 0000000..3d27afa --- /dev/null +++ b/C++/Easy/ForLoop.cpp @@ -0,0 +1,57 @@ +#include +#include +using namespace std; + +int main() { + // Complete the code. + int num1, num2; + cin >> num1 >> num2; + for (int i = num1; i <= num2; i++) + { + if(i == 1) + { + cout <<"one" < 0 else 0 + + # Calculate the side areas by checking adjacent cells + left_height = 0 if j == 0 else board[i][j - 1] + right_height = 0 if j == width - 1 else board[i][j + 1] + up_height = 0 if i == 0 else board[i - 1][j] + down_height = 0 if i == height - 1 else board[i + 1][j] + + side_area = max(0, cell_height - left_height) + max(0, cell_height - right_height) + max(0, cell_height - up_height) + max(0, cell_height - down_height) + + # Add the calculated areas to the total surface area + surface_area += top_bottom_area + side_area + +# Calculate the total price of the toy +price = surface_area + +# Print the price of the toy +print(price) diff --git a/Python/Medium/BiggerisGreater.py b/Python/Medium/BiggerisGreater.py new file mode 100644 index 0000000..8fcdffe --- /dev/null +++ b/Python/Medium/BiggerisGreater.py @@ -0,0 +1,31 @@ +def biggerIsGreater(w): + w = list(w) # Convert the string to a list for easy character manipulation + i = len(w) - 2 + + # Find the first character w[i] such that w[i] < w[i+1] + while i >= 0 and w[i] >= w[i + 1]: + i -= 1 + + if i == -1: + return "no answer" # The entire string is non-increasing + + # Find the rightmost character w[j] to the right of w[i] such that w[j] > w[i] + j = len(w) - 1 + while w[j] <= w[i]: + j -= 1 + + # Swap w[i] and w[j] + w[i], w[j] = w[j], w[i] + + # Reverse the substring to the right of w[i] + w[i + 1:] = reversed(w[i + 1:]) + + return ''.join(w) + +# Read the number of test cases +t = int(input().strip()) + +for _ in range(t): + w = input().strip() + result = biggerIsGreater(w) + print(result)