What is the objective of this question


  • 117

    This question is very unclear to me. what are we supposed to accomplish in this problem. Our read function returns an int but the expected result looks like its a String. if we are forced to read 4 chars at a time how do we ever read n chars that are not a factor of 4 if we actually use the read4 method? is 'n' the max we can return or must we return exactly n assuming at least n items exist other wise return the number of items. clearly I'm missing a lot here can someone please explain this problem to me.


  • 7
    I

    It assumes only read less than n chars, even if the there are more than n chars in a file.
    The question is not good...
    Here is my solution:
    https://leetcode.com/discuss/61942/ap-solution-c-0ms-4lines


  • 3

    Wow that's it. That isn't an interesting problem at all. Thanks for explaining


  • 25
    Y

    I agree with you . this is the most stupid problem among all problems in leetcode.


  • 6
    Z

    I spent several hours trying to understand this question, and I still don't get it. Now i'm flipped out. Is this really an interview question?


  • 2

    @zhongqi I asked this question four months ago and honestly i still don't get it. However if you see a question like this in a interview just ask TON!!! of questions to figure out what in the world they want you to do. They may purposely give you a weird question like this just to see how you respond.


  • 14
    N

    Actually, this question may be more practical than it looks like at your first glimpse.

    In reality, hw or system may have constraints for read from file system. eg. hardeware DMA engine may fetch data 128 bytes from disk. another example is that loading 4-bytes in aligned ddr should be obviously faster than load 1 byte 4 times. It is exactly same as read4 problem.

    interview question is in abstract.


  • 0

    Thanks for sharing.


  • 0
    L

    Didn't get it either lol, stupid question


  • 0

    Maybe return the buf as string instead of return final count, will make more sense, and it will then be the same style as the expected output.

    public int read(char[] buf, int n) {
            char[] tmp = new char[4];
            int res = 0, count = -1;
            while (res < n) {
                count = read4(tmp);
                if (count == 0) break;
                int r = n - res < count ? n - res : count;
                for (int i = 0; i < r; i++) {
                    buf[res++] = tmp[i];
                }
            }
            return res;
        }
    

  • 13

    Hello everyone, originally, I treat the buffer as the file that we read characters from, but in fact, it is a temporary array that store the characters we read. I didnt figure it out until I read some of others' solution . Is there anybody who used to understand it the same as me? Maybe I am too blunt at this time... Anyway I think this is an ambiguous question.


  • 0
    W

    This question is so unclear. I am sure when this question was asked it must have been backed up by a practical example. It will be great to have detailed explanation or examples or hints.


  • 1
    V

    I agree this is confusing. But after trial and error, and looking at the expected outputs for given inputs -- the problem is following

    Your objective is to return the number of characters actually read
    if you return that, the expected output is displaying what those characters are and checks if it is matching your output


  • 0
    B

    Whoever wrote the description for this problem is a fool.


  • 0
    F

    I'm over 200 questions completed so far, and this one is by far the stupidest question I've seen on LeetCode. It's just totally incomprehensible what the question is even asking for. Complete waste of time.


  • 0
    N

    For people saying this is the stupidest question they ever saw, mind that I was asked similar question in Google telephonic round


  • 0
    J

    @wxl163530 me too...


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.