मध्यम 0 हल किए गए 0% स्वीकृति

Champernowne Digits

Find digits at given positions of the string 123456789101112... made by writing out the counting numbers.

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

  • Count digits used by numbers of each length
  • Locate a number and digit from a position
  • Use 64-bit arithmetic safely

समस्या

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

Write the positive integers one after another: 123456789101112131415... Position 1 holds 1, position 10 holds the 1 of 10, position 11 the 0 of 10. For each requested position, find the digit there. The positions go far past what you could build as a string: skip whole blocks of numbers with the same number of digits (9 one-digit numbers, 90 two-digit numbers, 900 three-digit numbers, ...).

Implement champernowne_digits(positions).

Input

positions: Positions in the digit string, counting from 1.

Output

Return the digit at each position, in the same order as the input. An empty input returns an empty list.

सीमाएँ

0 ≤ positions.length ≤ 100; 1 ≤ position ≤ 10^15

उदाहरण

उदाहरण 1
इनपुट:
positions = [1, 9, 10, 11]

अपेक्षित आउटपुट:
expected = [1, 9, 1, 0]
इनपुट:
std::vector<long long> positions = {1, 9, 10, 11};

अपेक्षित आउटपुट:
std::vector<long long> expected = {1, 9, 1, 0};
इनपुट:
long[] positions = new long[] {1, 9, 10, 11};

अपेक्षित आउटपुट:
long[] expected = new long[] {1, 9, 1, 0};

व्याख्या

The string starts 1 2 3 4 5 6 7 8 9 1 0 1 1, so the digits are [1, 9, 1, 0].

उदाहरण 2
इनपुट:
positions = [15, 190]

अपेक्षित आउटपुट:
expected = [2, 1]
इनपुट:
std::vector<long long> positions = {15, 190};

अपेक्षित आउटपुट:
std::vector<long long> expected = {2, 1};
इनपुट:
long[] positions = new long[] {15, 190};

अपेक्षित आउटपुट:
long[] expected = new long[] {2, 1};

व्याख्या

Position 15 is the 2 of 12. Positions 10 to 189 hold 10 to 99, so 190 is the first digit of 100: [2, 1].

कैसे हल करें

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

संकेत 1

Numbers with d digits take 9 × 10^(d − 1) × d positions in total.

संकेत 2

Subtract whole blocks until the position falls inside one.

संकेत 3

Within the block, (position − 1) / d tells you which number and (position − 1) % d which digit.

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

O(m × log P) time for m positions, O(m) extra space

संदर्भ

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

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

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

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

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

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