Question: Please Fix the following method of the program in Java ( Only fix the text in bold ): import java.io.*; import java.util.*; import java.text.*; import
Please Fix the following method of the program in Java (Only fix the text in bold):


import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*;
public class Solution {
static int[] getRecommendedTweets(int[][] followGraph_edges, int[][] likeGraph_edges, int targetUser, int minLikeThreshold) { ArrayList targetUsersFollows = new ArrayList(); for(int i[]: followGraph_edges){ if(i[0] == targetUser){ targetUsersFollows.add(i[1]); } } Map recommendedTweetsPossiblities = new HashMap(); for(int j[]: likeGraph_edges){ int count = 0; if(targetUsersFollows.contains(j[0])){ if( recommendedTweetsPossiblities.containsKey(j[1]) ){ count = recommendedTweetsPossiblities.get(j[1]); } recommendedTweetsPossiblities.put(j[1], ++count); } } List notPopularTweets = new ArrayList(); for (Map.Entry temp : recommendedTweetsPossiblities.entrySet()) { if(temp.getValue() notPopularTweets.add(temp.getKey()); } } for(Iterator iterator = notPopularTweets.iterator(); iterator.hasNext(); ){ Integer key = iterator.next(); recommendedTweetsPossiblities.remove(key); } Set finalRecommendedTweets = recommendedTweetsPossiblities.keySet(); int ans[] = new int[finalRecommendedTweets.size()]; int index = 0; for(Integer element : finalRecommendedTweets) ans[index++] = element.intValue(); return ans; } }
public static void main(String[] args) throws IOException{
Scanner in = new Scanner(System.in);
final String fileName = System.getenv("OUTPUT_PATH");
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
int[] res;
String[] _followGraph_nodesm = in.nextLine().split(" ");
int _followGraph_nodes = Integer.parseInt(_followGraph_nodesm[0]);
int _followGraph_edges = Integer.parseInt(_followGraph_nodesm[1]);
int[] _followGraph_from = new int[_followGraph_edges];
int[] _followGraph_to = new int[_followGraph_edges];
for (int _followGraph_i = 0; _followGraph_i
String[] _followGraph_fromv = in.nextLine().split(" ");
_followGraph_from[_followGraph_i] = Integer.parseInt(_followGraph_fromv[0]);
_followGraph_to[_followGraph_i] = Integer.parseInt(_followGraph_fromv[1]);
}
String[] _likeGraph_nodesm = in.nextLine().split(" ");
int _likeGraph_nodes = Integer.parseInt(_likeGraph_nodesm[0]);
int _likeGraph_edges = Integer.parseInt(_likeGraph_nodesm[1]);
int[] _likeGraph_from = new int[_likeGraph_edges];
int[] _likeGraph_to = new int[_likeGraph_edges];
for (int _likeGraph_i = 0; _likeGraph_i
String[] _likeGraph_fromv = in.nextLine().split(" ");
_likeGraph_from[_likeGraph_i] = Integer.parseInt(_likeGraph_fromv[0]);
_likeGraph_to[_likeGraph_i] = Integer.parseInt(_likeGraph_fromv[1]);
}
// generate follow Graph
int[][] followGraph = new int[_followGraph_edges][2];
for (int i = 0; i
followGraph[i][0] = _followGraph_from[i];
followGraph[i][1] = _followGraph_to[i];
}
// generate like Graph
int[][] likeGraph = new int[_likeGraph_edges][2];
for (int i = 0; i
likeGraph[i][0] = _likeGraph_from[i];
likeGraph[i][1] = _likeGraph_to[i];
}
int _targetUser;
_targetUser = Integer.parseInt(in.nextLine().trim());
int _minLikeThreshold;
_minLikeThreshold = Integer.parseInt(in.nextLine().trim());
res = getRecommendedTweets(followGraph, likeGraph, _targetUser, _minLikeThreshold);
if (res == null) {
bw.write("Null Result");
bw.newLine();
bw.close();
return;
}
for(int res_i=0; res_i
bw.write(String.valueOf(res[res_i]));
bw.newLine();
}
bw.close();
}
}
On Twitter, millions of tweets are posted on a daily basis. Help Twitter write a simple ranking algorithm to find the best of all tweets. It works as follows: A good tweet receives many "likes" from people on Twitter, either from people you follow, or people you do not follow. A tweet is more relevant to you if people you follow also liked the tweet. If enough people you follow have liked that tweet, we recommend that tweet to you. Your task is to complete the function getRecommendedTweets(followGraph_edges, likeGraph_edges, targetUser, minLikeThreshold), which returns a list of tweet IDs in sorted order that should be recommended for a certain user. It takes 4 parameters: followGraph edges stores follow relationships as an array of tuple of integers. For example, followGraph_edges Arrayf(A, B), (A, C), (B, C) represents 3 follow relationships: A follows B A follows C B follows O -likeGraph edges stores like relationships, also in an array of tuple of integers. For example, likeGraph-edges = Array(A, T1), (B, T2), (A, T2)) means: A liked tweet T1 B liked tweet T2 A liked tweet T2 - targetUser is the user ID for which we generate recommended tweets On Twitter, millions of tweets are posted on a daily basis. Help Twitter write a simple ranking algorithm to find the best of all tweets. It works as follows: A good tweet receives many "likes" from people on Twitter, either from people you follow, or people you do not follow. A tweet is more relevant to you if people you follow also liked the tweet. If enough people you follow have liked that tweet, we recommend that tweet to you. Your task is to complete the function getRecommendedTweets(followGraph_edges, likeGraph_edges, targetUser, minLikeThreshold), which returns a list of tweet IDs in sorted order that should be recommended for a certain user. It takes 4 parameters: followGraph edges stores follow relationships as an array of tuple of integers. For example, followGraph_edges Arrayf(A, B), (A, C), (B, C) represents 3 follow relationships: A follows B A follows C B follows O -likeGraph edges stores like relationships, also in an array of tuple of integers. For example, likeGraph-edges = Array(A, T1), (B, T2), (A, T2)) means: A liked tweet T1 B liked tweet T2 A liked tweet T2 - targetUser is the user ID for which we generate recommended tweets
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
