Skip to content

Rotate_array_90degree added #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\msys64\\ucrt64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
71 changes: 71 additions & 0 deletions Array/Rotate_array_90degree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

#include <iostream>
#include <vector>
using namespace std;

void rotateMatrix(vector<vector<int>> &matrix)
{
int rows = matrix.size();
int cols = matrix[0].size();

// Create a new matrix to store rotated values
vector<vector<int>> rotated(cols, vector<int>(rows));

// Rotate the matrix (90 degrees clockwise)
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
rotated[j][rows - 1 - i] = matrix[i][j];
}
}

// Copy rotated matrix back to original matrix
matrix = rotated;
}

int main()
{
int rows, cols;
cout << "Enter number of rows: ";
cin >> rows;
cout << "Enter number of columns: ";
cin >> cols;

vector<vector<int>> matrix(rows, vector<int>(cols));

// Input matrix elements
cout << "Enter matrix elements:\n";
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> matrix[i][j];
}
}

cout << "\nOriginal Matrix:\n";
for (const auto &row : matrix)
{
for (int val : row)
{
cout << val << " ";
}
cout << endl;
}

// Rotate the matrix
rotateMatrix(matrix);

cout << "\nRotated Matrix (90 degrees clockwise):\n";
for (const auto &row : matrix)
{
for (int val : row)
{
cout << val << " ";
}
cout << endl;
}

return 0;
}
28 changes: 28 additions & 0 deletions Bitmasking/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\msys64\\ucrt64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
21 changes: 21 additions & 0 deletions Bitmasking/maximum_xor_2numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// C++ program to find the maximum
// XOR value of two elements in an array
#include <bits/stdc++.h>
using namespace std;

// Function to find the maximum XOR
int maxXOR(vector<int> &arr) {
int res = 0;
for (int i = 0; i < arr.size(); i++) {
for (int j = i + 1; j < arr.size(); j++) {
res = max(res, arr[i] ^ arr[j]);
}
}
return res;
}

int main() {
vector<int> arr = {25, 10, 2, 8, 5, 3};
cout << maxXOR(arr);
return 0;
}