समस्या
A rectangle has two sides of length width and two sides of length height. Its perimeter is the total length of all four sides.
Implement rectangle_perimeter(width, height).
Input
width: The width of the rectangle. height: The height of the rectangle.
Output
Return the perimeter as an integer.
सीमाएँ
1 ≤ width, height ≤ 1,000,000
उदाहरण
इनपुट:
width = 3
height = 5
अपेक्षित आउटपुट:
expected = 16
इनपुट:
long long width = 3;
long long height = 5;
अपेक्षित आउटपुट:
long long expected = 16;
इनपुट:
long width = 3;
long height = 5;
अपेक्षित आउटपुट:
long expected = 16;
व्याख्या
Two sides of 3 and two sides of 5: 3 + 3 + 5 + 5 = 16.
इनपुट:
width = 7
height = 7
अपेक्षित आउटपुट:
expected = 28
इनपुट:
long long width = 7;
long long height = 7;
अपेक्षित आउटपुट:
long long expected = 28;
इनपुट:
long width = 7;
long height = 7;
अपेक्षित आउटपुट:
long expected = 28;
व्याख्या
A square is a rectangle too: 4 × 7 = 28.
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Rectangle में दो बराबर widths और दो बराबर heights होती हैं.
संकेत 2
चारों sides जोड़ो, या पहले दो repeated side lengths combine कर लो.
संकेत 3
Integer arithmetic ही है; यहाँ किसी special case की जरूरत नहीं.
अपेक्षित जटिलता
समय O(1), अतिरिक्त स्थान O(1)
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।