आसान 0 हल किए गए 0% स्वीकृति

Chess Square Color

Determine the color of a square on an 8 by 8 board.

आप क्या सीखेंगे

  • Turn a square name into row and column numbers
  • Use parity to decide the color
  • Convert letters to numbers

समस्या

अनुवाद दिखाएँ

Use a board whose top-left square is white. Rows and columns start at 0 at the top left. Adjacent squares alternate colors. Return empty text for a position outside the board.

Implement chess_square_color(column, row).

Input

column: The column, counted from the left starting at 0.

row: The row, counted from the top starting at 0.

Output

Return white, black, or an empty string for invalid coordinates.

सीमाएँ

−10 ≤ column, row ≤ 20. Valid board coordinates are 0 through 7.

उदाहरण

उदाहरण 1
इनपुट:
column = 2
row = 3

अपेक्षित आउटपुट:
expected = "black"
इनपुट:
long long column = 2;
long long row = 3;

अपेक्षित आउटपुट:
std::string expected = "black";
इनपुट:
long column = 2;
long row = 3;

अपेक्षित आउटपुट:
string expected = "black";

व्याख्या

Five steps from the white corner change color an odd number of times.

उदाहरण 2
इनपुट:
column = 8
row = 0

अपेक्षित आउटपुट:
expected = ""
इनपुट:
long long column = 8;
long long row = 0;

अपेक्षित आउटपुट:
std::string expected = "";
इनपुट:
long column = 8;
long row = 0;

अपेक्षित आउटपुट:
string expected = "";

व्याख्या

Column 8 is outside the valid range 0 through 7.

कैसे हल करें

पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।

संकेत 1

Square color alternates with moves across rows and columns, so only the coordinate pattern matters.

संकेत 2

A parity check on row and column can tell you which color to return.

संकेत 3

Return empty text immediately when either coordinate is outside the 0 to 7 board range.

अपेक्षित जटिलता

O(1) time, O(1) extra space

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

हर कोडर का सबसे अच्छा पास हुआ समाधान। तेज़, कम मेमोरी वाले और बेहतर रेटिंग वाले समाधान ऊपर रहते हैं।

अभी कोई पास हुआ समाधान नहीं है। इसे हल करें और पहला स्थान पाएँ।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।