Python program for Friends on Facebook














































Python program for Friends on Facebook



                                   Friends on Facebook




There are N people P1, P2, P3, %u2026, PN having F1, F2, F3, %u2026, FN Facebook friends, respectively. The solution to this problem is finding k = Fi%Fj such that it is maximum over all valid i,j


Constraints:

2 <= N <= 105

1 <= Ai <= 109 for each i



Input Format:

The first line contains an integer N

The second line contains N space-separated integers F1, F2, F3, %u2026, FN


Example: Input: 5 1 2 3 4 5 Output: 4

Source code:


n = int(input())
l = [int(x) for x in input().split()]
m1 = max(l) ; m2 = 0
for i in l :
if i >m2 and i <m1:
m2 = i
print(m2%m1)


Screen Output:




More Articles of Bhanu Prakash Reddy M:

Name Views Likes
Python - Generic output formatting 360 11
Python - Standard Encodings in Binary Data service 330 29
Python - Stream Encoding and Decoding 379 16
Python - Stateless Encoding and Decoding in Binary data service 355 22
Python Binary Data Service Error Handlers 353 51
Python - Binary Data Services - 2 373 33
Python Binary Data Services 389 92
Python - Dijkstras shortest path algorithm 465 24
Python - Prims minimum spanning tree 403 22
Python - Cookies in CGI 346 23
Python CGI Environment Variables 377 20
CGI Programming-2 389 49
Python - CGI Programming 385 39
Python The Knights tour problem 537 47
Python User-defined Exceptions 626 57
Python Concrete exceptions part-2 630 28
Python Concrete exceptions 617 12
Python Built-in Exceptions 631 13
Python Program In-order traversal of a tree without using recursion 645 28
Python Program pre-order traversal of a tree without using recursion 639 29
Python Program post-order traversal of a tree without using recursion 652 22
Python Cryptographic Generating tokens 709 13
Python Cryptographic Secure hashes and message digests 697 65
Python Cryptographic Introduction 734 11
Python Generate secure random numbers 733 41
Python Random module --2 735 18
Python Random Module 736 22
Python IP Geolocation 754 13
Python Data Changes to GeoIP Legacy 749 10
Python Geoip Enriching MMDB files 758 16
Python The Easy Way to Use MaxMind GeoIP 795 25
Python Types of Anonymous IPs and How They Affect Your Business 774 19
Python GeoIP2 Databases with HAProxy Enterprise 773 25
Python Geoip Maxmind 798 34
Python Geoip2 Configuring geolocation 810 24
Python Geolocation with GeoIP2 807 61
Python GeoIP2 JavaScript Client API 814 33
Python GeoIP2 Precision Services 816 24
Python Geoip2 Modules 880 34
Python Geoip Database Reader Exceptions 880 30
Python MaxMind GeoIP2 863 33
Python program for panagram 891 30
Python program for Smallest Palindrome 916 13
Python program for Friends on Facebook 938 21
Python Program for Choosing Balls 896 17
Python program for frequency is a function that takes as input a list of integers and returns a pair of the form (minfreqlist,maxfreqlist) 928 42
Python Program for Rotate Matrix Elements 895 11
GeoIP -- Flask. 911 15
Geoip-IP geolocation information in Python. 908 15
GeoIP - MaxMind GeoIP2 API 918 21
Python Program 919 20
Python program for Domino Solitaire 924 22
Python-- Programs 910 14
Plotting Series in Python 930 24
GeoIP in PYTHON 964 23

Comments