Feeling like a failure because of a class
What you may be experiencing is the fact that insight into some areas of mathematics don't translate into insight into others. I had a lot of insight into Analysis (my field) and General Topology, but little in Abstract Algebra. I once took a course (grad level) in discrete math and did terribly, experiencing much of what you describe. 

To be successful you need a fairly general understanding of much (but not all) of mathematics and a deep understanding of one or two narrow areas. If you can achieve that then you can be a success. 

It hasn't been possible for an individual to understand (at any deep level) all of mathematics for about 100 years. There are likely only a few living computer science professionals that understand all of CS, if that is even possible at all anymore, given what has gone on in the last 10 years or so. 

If you are early in your studies then work on breadth. If you are mid to late, then it is time for a deep dive.