There are N rectangles numbered from 0 to N-1. The K-th rectangle has size A[K] × B[K].
We want to arrange as many rectangles as possible into a strip. The rectangles can be arranged into a strip if they all share a side of the same length (which becomes the height of the strip). Note that rectangles can be rotated.
Write a function:
int solution(vector<int> &A, vector<int> &B);
that, given two arrays A and B of N integers each, returns the maximum number of rectangles that can be arranged into a strip.
Examples:
1. Given A = [2, 3, 2, 3, 5] and B = [3, 4, 2, 4, 2], the function should return 3. Choosing the 0th, 2nd and 4th rectangles we can obtain the following strip of height 2 (note that the 0th rectangle was rotated):
We can also choose the 0th, 1st and 3rd rectangles to obtain a strip of height 3. Here we have rotated 1st and 3rd rectangles:
2. Given A = [2, 3, 1, 3] and B = [2, 3, 1, 3], the function should return 2. We can choose the 1st and 3rd rectangles:
3. Given A = [2, 10, 4, 1, 4] and B = [4, 1, 2, 2, 5], the function should return 3. We can choose the 0th, 2nd and 4th rectangles to obtain a strip of height 4:
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- arrays A and B both consist of N integers;
- each element of arrays A and B is an integer within the range [1..1,000,000,000].
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (auto index = 0; i <)
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (auto index = 0; i < )
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (auto index = 0; i < A.size())
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (auto index = 0; index < A.size();)
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (auto index = 0; index < A.size(); ++index)
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t index = 0; index < A.size(); ++index)
{
if (A)
}
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i])
}
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
}
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A:" << A << endl;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A:" << A << endl;
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A:" << A << endl;
cout << "B:" << B << endl;
return A.size();
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:20:18: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'std::vector<int>') cout << "A:" << A << endl; ~~~~~~~~~~~~~^~~~ In file included from /opt/lang/gcc/include/c++/6.2.0/iostream:39:0, from solution.cpp:4: /opt/lang/gcc/include/c++/6.2.0/ostream:108:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] operator<<(__ostream_type& (*__pf)(__ostream_type&)) ^~~~~~~~ /opt/lang/gcc/include/c++/6.2.0/ostream:108:7: note: no known conversion for argument 1 from 'std::vector<int>' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}' /opt/lang/gcc/include/c++/6.2.0/ostream:117:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>] operator<<(__ios_type& (*__pf)(__ios_type&)) ^~~~~~~~ /opt/lang/gcc/include/c++/6.2.0/ostream:117:7: note: no known conversion for argument 1 from 'std::vector<int>' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}' /opt/lang/gcc/include/c++/6.2.0/ostream:127:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostre
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
for (size_t i = 0; i < A.size(); ++i)
cout << "A:" << A << endl;
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
for each (size_t i = 0; i < A.size(); ++i)
cout << "A:" << A << endl;
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
for each (auto e: A.size(); ++i)
cout << "A:" << A << endl;
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
for each (auto e: A)
cout << "A:" << A << endl;
for each (auto e: A)
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A:" << A << endl;
for each (auto e: A)
cout << "A:" << A << endl;
cout << "B:" << B << endl;
for each (auto e: A)
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [" << A << endl;
for each (auto e: A)
cout << "A:" << A << endl;
cout << "B: ";
for each (auto e: A)
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for each (auto e: A)
cout << "A:" << A << endl;
cout << "B: ";
for each (auto e: A)
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for each (auto e: A)
cout << e << " ";
cout << "B: ";
for each (auto e: A)
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for each (auto e: A)
cout << e << " ";
cout << "B: [";
for each (auto e: A)
cout << e << " ";
cout << "B:" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for each (auto e: A)
cout << e << " ";
cout << "B: [";
for each (auto e: A)
cout << e << " ";
cout << "]" << B << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for each (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for each (auto e: A)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:21:9: error: expected '(' before 'each' for each (auto e: A) ^~~~ func.cpp:21:15: error: expected primary-expression before 'auto' for each (auto e: A) ^~~~ func.cpp:21:24: error: 'each' was not declared in this scope for each (auto e: A) ^ func.cpp:25:19: error: expected ')' before ';' token cout << "B: ["; ^ func.cpp:26:9: error: expected '(' before 'each' for each (auto e: A) ^~~~ func.cpp:26:15: error: expected primary-expression before 'auto' for each (auto e: A) ^~~~ func.cpp:26:24: error: 'each' was not declared in this scope for each (auto e: A) ^ func.cpp:30:5: error: expected primary-expression before 'return' return A.size(); ^~~~~~ func.cpp:30:5: error: expected ')' before 'return' func.cpp:31:1: warning: control reaches end of non-void function [-Wreturn-type] } ^
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for each (auto e: A)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
A: [2 3 2 3 2 ] B: [2 3 2 3 2 ]
A: [2 3 1 3 ] B: [2 3 1 3 ]
A: [2 1 2 1 4 ] B: [2 1 2 1 4 ]
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
A: [2 3 2 3 2 ] B: [3 4 2 4 5 ]
A: [2 3 1 3 ] B: [2 3 1 3 ]
A: [2 1 2 1 4 ] B: [4 10 4 2 5 ]
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
// sort each array to find
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
// sort each array to find longest sequence
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
// sort each array to find longest sequence
std::sort(A);
std::sort(B);
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A);
std::sort(B);
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A);
std::sort(B);
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:21:5: error: 'sort' is not a member of 'std' std::sort(A); ^~~ func.cpp:22:5: error: 'sort' is not a member of 'std' std::sort(B); ^~~
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A);
std::sort(B);
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A);
std::sort(B);
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:20:16: error: no matching function for call to 'sort(std::vector<int>&)' std::sort(A); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/algorithm:62:0, from func.cpp:1: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:4697:5: note: candidate: template<class _RAIter> void std::sort(_RAIter, _RAIter) sort(_RandomAccessIterator __first, _RandomAccessIterator __last) ^~~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:4697:5: note: template argument deduction/substitution failed: func.cpp:20:16: note: candidate expects 2 arguments, 1 provided std::sort(A); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/algorithm:62:0, from func.cpp:1: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:4727:5: note: candidate: template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare) sort(_RandomAccessIterator __first, _RandomAccessIterator __last, ^~~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:4727:5: note: template argument deduction/substitution failed: func.cpp:20:16: note: candidate expects 3 arguments, 1 provided std::sort(A); ^ func.cpp:21:16: error: no matching function for call to 'sort(std::vector<int>&)' std::sort(B); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/algorithm:62:0, from func.cpp:1: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:4697:5: note: candidate: template<class _RAIter> void std::sort(_RAIter, _RAIter) sort(_RandomAccessIterator __first, _RandomAccessIterator __last) ^~~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:4697:5: note: template argument deduction/substitution failed: func.cpp:21:16: note: candidate expects 2 arguments, 1 provided std::sort(B); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/algorithm:62:0, from func.cpp:1: /opt/lang/g
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B);
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
A: [2 2 2 3 3 ] B: [2 3 4 4 5 ]
A: [1 2 3 3 ] B: [1 2 3 3 ]
A: [1 1 2 2 4 ] B: [2 4 4 5 10 ]
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
for (auto e: A)
cout << e << " ";
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
for (auto e: A)
{
cout << e << " ";
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
for (auto e: A)
{
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
for (auto e: A)
{
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
for (auto e: A)
{
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
for (auto e: A)
{
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
for (auto e: A)
{
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto check = A[0];
for (auto e: A)
{
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto check = A[0];
for (auto e: A)
{
if ()
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto max_count = 0;
auto check = A[0];
for (auto e: A)
{
if ()
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
for (auto e: A)
{
if (e == check)
cout << e << " ";
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
for (auto e: A)
{
if (e == check)
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
auto chunk_size = 1;
auto check = A[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_cou)
}
}
auto chunk_size = 1;
auto check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
auto chunk_size = 1;
auto check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
}
}
return A.size();
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
auto chunk_size = 1;
auto check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
auto chunk_size = 1;
auto check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
return max_count;
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:51:13: error: 'chunck_size' was not declared in this scope chunck_size = 1; ^~~~~~~~~~~ func.cpp:56:10: error: conflicting declaration 'auto chunk_size' auto chunk_size = 1; ^~~~~~~~~~ func.cpp:38:10: note: previous declaration as 'int chunk_size' auto chunk_size = 1; ^~~~~~~~~~ func.cpp:57:10: error: conflicting declaration 'auto check' auto check = B[0]; ^~~~~ func.cpp:39:10: note: previous declaration as 'int check' auto check = A[0]; ^~~~~ func.cpp:68:13: error: 'chunck_size' was not declared in this scope chunck_size = 1; ^~~~~~~~~~~
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
size_t chunk_size = 1;
auto check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
return max_count;
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:51:13: error: 'chunck_size' was not declared in this scope chunck_size = 1; ^~~~~~~~~~~ func.cpp:68:13: error: 'chunck_size' was not declared in this scope chunck_size = 1; ^~~~~~~~~~~
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunck_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunck_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 1;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
return max_count;
}
A: [2 2 2 3 3 ] B: [2 3 4 4 5 ]
A: [1 2 3 3 ] B: [1 2 3 3 ]
A: [1 1 2 2 4 ] B: [2 4 4 5 10 ]
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 0;
max_count = std::max(chunk_size, max_count);
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
chunk_size = 1;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
check = e;
chunk_size = 1;
max_count = std::max(chunk_size, max_count);
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
return max_count;
}
A: [2 2 2 3 3 ] B: [2 3 4 4 5 ]
A: [1 2 3 3 ] B: [1 2 3 3 ]
A: [1 1 2 2 4 ] B: [2 4 4 5 10 ]
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
return max_count;
}
A: [2 2 2 3 3 ] B: [2 3 4 4 5 ]
A: [1 2 3 3 ] B: [1 2 3 3 ]
A: [1 1 2 2 4 ] B: [2 4 4 5 10 ]
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
//
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
int solution(vector<int> &A, vector<int> &B) {
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
int solution(vector<int> &A, vector<int> &B) {
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
int solution(vector<int> &A, vector<int> &B) {
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
int solution(vector<int> &A, vector<int> &B) {
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, >
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int>
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> dimension_count_by
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_dimension_count_by
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] == B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] == B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
std::swap(A[i], B[i]);
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
cout << e << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
cout << e.first << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
cout << e.first << " = " << e.second;
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
cout << e.first << " = " << e.second << " ";
cout << "]" << endl;
return max_count;
}
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
cout << e.first << " = " << e.second << " ";
cout << "]" << endl;
auto max_count = 1;
return max_count;
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:79:5: error: 'map' is not a member of 'std' std::map<int, int> element_count_by_dimension; ^~~ func.cpp:79:14: error: expected primary-expression before 'int' std::map<int, int> element_count_by_dimension; ^~~ func.cpp:83:9: error: 'element_count_by_dimension' was not declared in this scope element_count_by_dimension[A[i]]++; ^~~~~~~~~~~~~~~~~~~~~~~~~~ func.cpp:92:18: error: 'element_count_by_dimension' was not declared in this scope for (auto e: element_count_by_dimension) ^~~~~~~~~~~~~~~~~~~~~~~~~~
#include <algorithm>
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
cout << e.first << " = " << e.second << " ";
cout << "]" << endl;
auto max_count = 1;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
cout << e.first << " = " << e.second << " ";
cout << "]" << endl;
auto max_count = 1;
return max_count;
}
D: [2 = 3 3 = 3 4 = 2 5 = 1 ]
D: [1 = 1 2 = 1 3 = 2 ]
D: [1 = 2 2 = 3 4 = 3 5 = 1 10 = 1 ]
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
cout << e.first << " = " << e.second << " ";
cout << "]" << endl;
auto max_count = 1;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
}
cout << "]" << endl;
auto max_count = 1;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
auto max_count = 0;
cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
}
cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
auto max_count = 0;
cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
max_count = std::max(chunk_size, max_count);
}
cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
auto max_count = 0;
cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
max_count = std::max(e, max_count);
}
cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
auto max_count = 0;
cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
max_count = std::max(e, max_count);
}
cout << "]" << endl;
return max_count;
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:98:42: error: no matching function for call to 'max(std::pair<const int, int>&, int&)' max_count = std::max(e, max_count); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39:0, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&) max(const _Tp& __a, const _Tp& __b) ^~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:219:5: note: template argument deduction/substitution failed: func.cpp:98:42: note: deduced conflicting types for parameter 'const _Tp' ('std::pair<const int, int>' and 'int') max_count = std::max(e, max_count); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39:0, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare) max(const _Tp& __a, const _Tp& __b, _Compare __comp) ^~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:265:5: note: template argument deduction/substitution failed: func.cpp:98:42: note: deduced conflicting types for parameter 'const _Tp' ('std::pair<const int, int>' and 'int') max_count = std::max(e, max_count); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/algorithm:62:0, from func.cpp:1: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:3459:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>) max(initializer_list<_Tp> __l) ^~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
max_count = std::max(e, max_count);
}
cout << "]" << endl;
return max_count;
}
func.cpp: In function 'int solution(std::vector<int>&, std::vector<int>&)': func.cpp:98:42: error: no matching function for call to 'max(std::pair<const int, int>&, int&)' max_count = std::max(e, max_count); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39:0, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&) max(const _Tp& __a, const _Tp& __b) ^~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:219:5: note: template argument deduction/substitution failed: func.cpp:98:42: note: deduced conflicting types for parameter 'const _Tp' ('std::pair<const int, int>' and 'int') max_count = std::max(e, max_count); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39:0, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare) max(const _Tp& __a, const _Tp& __b, _Compare __comp) ^~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:265:5: note: template argument deduction/substitution failed: func.cpp:98:42: note: deduced conflicting types for parameter 'const _Tp' ('std::pair<const int, int>' and 'int') max_count = std::max(e, max_count); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/algorithm:62:0, from func.cpp:1: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:3459:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>) max(initializer_list<_Tp> __l) ^~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
max_count = std::max(e., max_count);
}
cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
cout << "]" << endl;
return max_count;
}
D: [2 = 3 3 = 3 4 = 2 5 = 1 ]
D: [1 = 1 2 = 1 3 = 2 ]
D: [1 = 2 2 = 3 4 = 3 5 = 1 10 = 1 ]
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
[2,2,2][3,4,5]
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
[[2, 2, 2], [3, 4, 5]]
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
[[2], [3]]
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
[[2], [3]]
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
[[2], [3]]
#include <algorithm>
#include <map>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
// commented code v1
/*
// avoid complexify code below
if (A.size() == 0)
return 0;
// prepare arrays, transform rectangles so
// that smaller side trap int A and bigger side trap into B
for (size_t i = 0; i < A.size(); ++i)
{
if (A[i] > B[i])
{
std::swap(A[i], B[i]);
}
}
// sort each array to find longest sequence
std::sort(A.begin(), A.end());
std::sort(B.begin(), B.end());
cout << "A: [";
for (auto e: A)
cout << e << " ";
cout << "]" << endl;
cout << "B: [";
for (auto e: B)
cout << e << " ";
cout << "]" << endl;
auto max_count = 0;
auto chunk_size = 0;
auto check = A[0];
// todo use adjucent_find()
for (auto e: A)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
chunk_size = 0;
check = B[0];
for (auto e: B)
{
if (e == check)
{
chunk_size++;
}
else
{
max_count = std::max(chunk_size, max_count);
check = e;
chunk_size = 1;
}
}
max_count = std::max(chunk_size, max_count);
*/
int solution(vector<int> &A, vector<int> &B) {
std::map<int, int> element_count_by_dimension;
for (size_t i = 0; i < A.size(); ++i)
{
element_count_by_dimension[A[i]]++;
if (A[i] != B[i])
{
element_count_by_dimension[B[i]]++;
}
}
int max_count = 0;
//cout << "D: [";
for (auto e: element_count_by_dimension)
{
//cout << e.first << " = " << e.second << " ";
max_count = std::max(e.second, max_count);
}
//cout << "]" << endl;
return max_count;
}
The solution obtained perfect score.