u/AdVisible6484

TLE while submitting but not when running separately..

For the recent Biweekly Contest : 3923. Minimum Generations to Target Point

I have written a brute force approach.

class Solution {
public:
    int minGenerations(vector<vector<int>>& points, vector<int>& target) {
        



        if(find(points.begin(), points.end(),target)!=points.end()) return 0;
        if(points.size()<=1) return -1;
        set<vector<int>> gen;
        set<vector<int>> parent;
        for(int i=0;i<points.size();i++)
        {
            parent.insert(points[i]);
        }
        int generation = 1;
        while(true){
                for(auto it1=parent.begin(); it1!=parent.end();it1++)
                    {
                        vector<int> v1 = *it1;
                        for(auto it2= next(it1);it2!=parent.end();it2++)
                        {
                            vector<int> res;
                            vector<int> v2 = *it2;
                            for(int i=0;i<3;i++)
                            {
                                int m = (v1[i]+v2[i])/2;
                                res.push_back(m);
                            }
                            gen.insert(res);
                            if(res==target) return generation;
                        }
                        
                    }
                    int prevSize=parent.size();
            parent.merge(gen);
            int newSize = parent.size();
            if(prevSize==newSize) return -1;
            gen.clear();
            generation++;
        }
    }
};

Now the testcase 948 / 949:

points = [[6,5,0],[0,5,6],[6,0,6]]

target = [0,0,0]

It is executing succesfully when I am running the testcase but when I am submitting its giving TLE.

Any suggestions on how I could improve this.

reddit.com
u/AdVisible6484 — 3 days ago

How do I actually THINK of a solution?

I am an below average coding person. I have solved about 400 Leetcodes.
I just dont get it. When I see a problem I can never think of a solution , but when I see a solution I can understand it.
Millions of time I have tried to restart dsa from arrays but I just don't get it. The logic never comes to me.
The backlog I have is I am "mentally lazy", in working out the dry runs. Dry runs are somehow really painful to me, which could be one of the reason.

But I really wanna improve. I have tried to create roadmaps, watched dozens to tutorials on roadmap, but no use.

From experienced people, please please help me point out what could I be doing wrong? What is the most optimal way to get this through. I am mildly consistent. I try to solve the daily problem and the simple ones I can do it.

But the ones where we have to create an algorithm ourselves is what breaks me, like the recent Dialy problem.

I will really appreciate some advice on what I am doing wrong, I am not able to point out what I am messing up in the thinking and practicing process.
Thank you in advance.

Also those 400 problems I have solved while watching tutorials, so I won't really attribute them to myself.

reddit.com
u/AdVisible6484 — 7 days ago

So the Owning side is the Problem enitity and the inverse is the Tags Entity.

(name = "problem")
public class Problem {

    String problemCode
;

    
    (strategy = GenerationType.
IDENTITY
)
    Long problemId
;

    
    String problemName
;
    
String contest
;
    
String platform
;

    
(EnumType.
STRING
)
    Status status
;

    
/*
    * when user sends in the payload the tags are going to be a list of strings containing the tag name
    * it will throw an error for tagset cuz it expects a set of tags object.
    * So through this field, set of strings we can it the input
    * process it in the problem service layer by calling the agservice methos that convert the set of strings
    * to set of Tags object
    * After which we set the tagset value to the returned value, to ensure consistent type handling.
    * it is marked as  because: we dont want to create any field in the database for this strings set. it is used just for the
    * input processing purpose.*/
    
    Set<String> tags
;

    
String url
;
    
String notes
;

    
/*
    * JsonIgnore cuz we don't want to see the whole tags set in the response output at all.*/
    
    
    (name="problem_tag"
,
     
joinColumns = (name = "problemId")
,
     
inverseJoinColumns = u/JoinColumn(name = "tagId")
    )
    Set<Tags> tagSet = new HashSet<>()
;
}

This is the tags entity.

(name="tags")
public class Tags {

    
    (strategy = GenerationType.
IDENTITY
)
    Long tagId
;

    
(unique = true
, 
nullable = false)
    String tagName
;

    
u/ManyToMany(mappedBy = "tagSet")
    Set<Problem> problemSet = new HashSet<>()
;
}

The controller for the /GET problem is

public ResponseEntity<List<Problem>> getAllProblems(@RequestParam(required = false) String status
, 
(required = false) String platform
,
                                                    
u/RequestParam(required = false) List<String> tags)
{

    List<Problem> problems = problemService.getAllProblems(status
, 
platform
, 
tags)
;
    
return new ResponseEntity<>(problems
, 
HttpStatus.
OK
)
;
}

So in the db it is creating a joined table as "problem_tag". I dont want to use JPA Specifications as of yet.

I want to learn how to implement it such that I am querying just the filtered problem list using the joined table... instead of querying the whole thing first and then filtering.

As I read in the documentation that for many-to-many this is how we represent it in db, I dont understand how that join table is getting used.

I am still learning spring boot, so I am focusing on these things.

Thank you for your help. I will really appreaciate your direction and help.

reddit.com
u/AdVisible6484 — 12 days ago

I know javascript, html, css very well. All of my projects (spring boot, mern) are just left at backend. I am not able to proceed with frontend. I am trying to learn from chatgpt but it has lead me no where till now. I feel awful being that dependent on AI just post a success message to the user.

I really want some fresh guidance on frontend... any framework that is preferable. AI is ruining the thing for me. Learning frontend from AI made things so much worse for me .

Someone please please help me out. or if there is something else I should try for frontend.

reddit.com
u/AdVisible6484 — 19 days ago
▲ 23 r/react

I know javascript, html, css very well. All of my projects are just left at backend. I am not able to proceed with frontend. I am trying to learn from chatgpt but it has lead me no where till now. I feel awful being that dependent on AI just post a success message to the user.
Someone please please help me out. or if there is something else I should try for frontend.

reddit.com
u/AdVisible6484 — 19 days ago