instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Suggest a completion to the following python code to print the sum of the squares of all numbers from 1 to a given number. The code should be optimized to have a time complexity of O(1) and a space complexity of O(1). Additionally, the input number should be a positive integer greater than 1.
number = 5
result = 0
fo... | codefeedback |
Create an HTML NavBar with five links: Home, About, Services, Blog, and Contact. Clicking on any of these links should take the user to the respective pages. The NavBar should have a logo on the left side and a dropdown menu on the right side. The dropdown menu should contain two options: Login and Sign Up. | codefeedback |
Update the given function to return the greatest common divisor of two numbers.
def divisor_function(a, b):
"""Returns the greatest common divisor of two numbers."""
if a < b:
a, b = b, a
# Step 1: Check if both numbers are equal, in which case the greatest common divisor is the number itself
... | codefeedback |
Write an SQL query to find the name of customers who have ordered at least three different items this month and the total quantity ordered by each customer should be greater than 5. Additionally, include the total price of the orders made by each customer. | codefeedback |
Using the given list of names, create a new set that contains only the names with length greater than 6 and do not contain any repeating characters. If there are no such names, return an empty set. Additionally, your solution must be implemented using only basic data structures (arrays, linked lists, etc.) and must not... | codefeedback |
Produce a snippet of C++ code to subtract two given numbers a and b, where the value of a is a floating-point number and the value of b is an integer. The result should be rounded to the nearest whole number. Additionally, if the result is positive, print "Positive", if the result is negative, print "Negative", and if ... | codefeedback |
Assign a class of 'active' to the last <a> element in the given HTML code, but only if it contains a specific data attribute. The solution must use recursion and handle a maximum depth of 10 levels. | codefeedback |
Write a JavaScript function to convert the given 12-hour time format to 24-hour format. The input time will always be a valid time in the format "hh:mm AM/PM", where "hh" represents the hours (00 to 12), "mm" represents the minutes (00 to 59), and "AM" or "PM" represents the time of day. The function should return the ... | codefeedback |
Create a function that takes in a list of integers and returns the sum of all the elements in the list. However, the function should not use any built-in sum() or reduce() functions to calculate the sum. The function should also have a time complexity of O(n), where n is the length of the input list. | codefeedback |
Describe an algorithm to convert an array of numbers into an array of its cubes, but do not use any arithmetic operators or built-in functions to calculate the cubes. | codefeedback |
Write a SQL query to generate a report which displays the total number of customers in each country, excluding countries with less than 10 customers. Additionally, display the percentage of customers in each country compared to the total number of customers. | codefeedback |
Suggest the best algorithm to reverse a string without using any additional data structures and with a time complexity of O(n), where n is the length of the string. However, you are not allowed to use any built-in string manipulation functions or methods, such as reverse(). | codefeedback |
Sort the given list in descending order using modified insertion sort in Python:
list = [1,12,1,4,8,10,13,17,6,3]
- The modified insertion sort should not use any built-in sorting functions or methods.
- The modified insertion sort should be implemented as a recursive function.
- The modified insertion sort should hav... | codefeedback |
Write a SQL query to group the records from a table named 'countries' by their population greater than 1 billion and whose land area is less than 10,000 square kilometers. | codefeedback |
Write a code to add two integers without any type conversion, using only bitwise operators. Additionally, you are not allowed to use the "+" operator. | codefeedback |
Write a MySQL query to count the number of book titles in the 'books' table having the word 'the' at the beginning of their title and ending with the letter 's', but also ignore any books with the word 'a' or 'an' in their title. | codefeedback |
Create a shell script to find the first ten prime numbers within a given range of 1000 to 2000. The script should output the sum of these prime numbers at the end. Additionally, the script should also output the average of these prime numbers rounded to two decimal places.
Furthermore, the script should handle any err... | codefeedback |
Write a SQL query that returns the sum of the values in a 'salary' column in a table named 'employees' for all employees who have been with the company for at least 5 years and have a job title of 'Manager'. | codefeedback |
Explain why software design patterns are important in software development and provide a real-life example where implementing a design pattern would enhance the efficiency or performance of a software system. Additionally, analyze the potential drawbacks or limitations of using design patterns in software development a... | codefeedback |
Create a C++ program to print a pattern's series of prime numbers, where the pattern is a diagonal of prime numbers in a square matrix. The size of the matrix should be a prime number. | codefeedback |
Write an SQL query to retrieve the employee's name, age, and the total number of employees who are older than them, from a table with the employee's id, name, and age. The result should be ordered by the employee's id in ascending order.
Additionally, include a column that displays the percentage of employees who are ... | codefeedback |
Write an HTML code to design a form which contains three fields: Name, Age, and Email. The form should have a button with text "Submit".
Additional Requirements:
1. Implement client-side validation for all three fields to ensure they are not left empty.
2. Implement server-side validation to check if the entered emai... | codefeedback |
Write a Perl program to remove the last element from an array of strings that contain lowercase and uppercase letters, numbers, and special characters, and return the resulting array. | codefeedback |
Convert the following matrix into a list of lists in Python. The matrix contains n rows and m columns, where n and m are positive integers. The elements in each row are in ascending order, and the elements in each column are in descending order. Additionally, the matrix contains duplicate elements. Find an algorithm wi... | codefeedback |
Write a Java code to create multiple threads, where each thread performs a specific task. Each task should involve multiple steps and require complex logical reasoning. The code should ensure that the threads are synchronized and communicate with each other using shared memory. Additionally, each thread should have a p... | codefeedback |
Write a Bash script which will retrieve system information, including memory usage, disk space usage, network bandwidth usage, and CPU usage. The script should also display the top 5 processes consuming the most memory and CPU. Additionally, the script should calculate the average CPU usage over a specific time period ... | codefeedback |
Implement a for loop in Python to iterate through a given list of numbers and print the square of each number, but only if the number is prime.
[1, 2, 3, 4, 5, 6, 7] | codefeedback |
Create a SQL query that lists all entries from a table that have a given parameter in the distinct column and have a specific condition met, while also ordering the results in descending order based on the employee's salary. Additionally, only include entries where the employee's age is greater than 25.
Table: employee... | codefeedback |
Create a C++ class called Employee with four data fields: age (an integer), name (a string), salary (a floating-point number), and a vector of strings called "projects" that stores the names of the projects the employee has worked on.
The Employee class should have the following member functions:
1. A constructor tha... | codefeedback |
Find the square root of a floating-point number without using any built-in functions or libraries. The number should be rounded to the nearest integer. The input number will always be positive and less than or equal to 10^6.
A = 9.0 | codefeedback |
Implement a Python program to calculate the median of a list of integers, but with the following added requirements:
1. The program should be able to handle input lists of any length, from 1 to 10^9.
2. The program should be able to handle input lists with duplicate elements.
3. The program should not use any built-in... | codefeedback |
Create a for loop in C++ to print out the sum of all the even numbers from 0 to a given number. Additionally, calculate and display the product of all the even numbers in the given range. | codefeedback |
Create a method in Java that takes an array of integers and finds the maximum value that is divisible by 3, 5, and 7. | codefeedback |
Using the comment as a guide, edit the code to handle the error appropriately and also implement a retry mechanism for the API call.
try:
# TODO: Implement retry mechanism for API call
# TODO: Make API call
except ConnectionError as ce:
# TODO: Handle connection error
except TimeoutError as te:
# TODO: ... | codefeedback |
Create a JavaFX program that allows a user to move a square shape in 3 different directions using the arrow keys. Additionally, implement collision detection to prevent the square from overlapping with any other shapes on the screen. The collision detection should be optimized for handling hundreds of shapes on the scr... | codefeedback |
Using JavaScript, create a function called "encryptMessage" that takes in a string as input and returns an encrypted version of the message.
The encryption algorithm should work as follows:
1. Convert each character in the input string to its ASCII value.
2. Increment the ASCII value of each character by a randomly ge... | codefeedback |
Create an HTML page with a table that contains ten rows and ten columns. The table should have alternating background colors for each row, where the background color of the first row should be white. Additionally, the table cells in the diagonal should have a different background color than the rest of the cells, and t... | codefeedback |
Create a function in Haskell that takes a non-negative integer less than or equal to 10^9 and returns a string representing its factorial. Your solution should be able to handle large inputs efficiently.
Additionally, implement a check to ensure that the input is within the given constraints. If the input is invalid, ... | codefeedback |
Implement a function that returns the reversed version of a given string, but do not use any built-in string reversal functions or methods, and ensure that the time complexity of the solution is O(n). | codefeedback |
Write a JavaScript function to sort the characters of a string in descending order based on their ASCII values.
#Example#
**Input:**
"hello"
**Output:**
"ollhe"
#Additional Information#
- The input string will only contain lowercase letters.
- The output string should not contain any repeated characters.
- Your so... | codefeedback |
Write a Java program that takes an array of integers and prints the numbers that are divisible by both 5 and 7, while excluding any numbers that are also divisible by 3. | codefeedback |
Design a function which takes an array of integers as input and returns the largest number in the array, without using any built-in sorting or max functions. The function should have a time complexity of O(n), where n is the length of the array. | codefeedback |
Create a Java method to interpret a given string into an integer, but without using any built-in parsing or conversion functions. The method should handle positive and negative integers and should return 0 if the string cannot be interpreted as an integer. Additionally, the method should also handle overflow cases, whe... | codefeedback |
Create an algorithm that iterates through a given string and returns the number of unique alphabets present in the string. The string may contain uppercase and lowercase letters. Ignore any non-alphabet characters and consider only English alphabets. The algorithm should also ignore repeated occurrences of the same alp... | codefeedback |
Design a C++ class to count the occurrences of a character in a given string, without using any built-in string functions or standard library functions. The solution should handle case sensitivity and allow for multiple characters to be counted simultaneously. Additionally, the class should implement a method to return... | codefeedback |
Write a function in R that takes a vector as an argument and returns a new vector in which each element is the sum of that element with its two neighbors from the original vector, but with a twist - if the sum of the three elements is a multiple of 3, the resulting element should be the product of the three elements in... | codefeedback |
Design a function which prints all the permutations of a given list of numbers, while also counting the total number of permutations and returning it as a result. However, you are not allowed to use any built-in functions or libraries that directly generate permutations. You need to implement the permutation algorithm ... | codefeedback |
Given an XML document containing information about a collection of books, write a program that uses XSLT transformation to parse the XML and generate an HTML table. The table should display the book title, author name(s), publishing year, and genre. Additionally, the table should be sorted in descending order based on ... | codefeedback |
Find the minimum value from a given array. However, you are not allowed to use any built-in functions or methods for finding the minimum value (e.g. min() function, sorting the array and taking the first element, etc.). You must come up with your own algorithm to solve this problem. The array may contain both positive ... | codefeedback |
Implement a data structure in Java that implements a stack with the following methods: 'push', 'pop', 'peek', 'isEmpty', and 'getSize'. The 'getSize' method should return the number of elements currently in the stack. Additionally, the implementation should throw a custom exception called 'StackUnderflowException' if '... | codefeedback |
Design a function in Python to toggle whether a given HTML tag has a given class and remove any other classes present in the tag. The function should also handle nested HTML tags.
## Erroneous Code Example ##
def toggle_class(tag: str, class_name: str) -> str:
tag = tag.replace('<div class="', '<div id="') # Inco... | codefeedback |
Describe how a doubly linked list data structure works in pseudo code, including functions to add a node at the beginning and end of the list, and a function to remove a specific node from the list. Additionally, implement a function to reverse the order of the list in-place.
The time complexity of each operation shou... | codefeedback |
Create a new array of integers which contains the sum of corresponding elements of two existing arrays. However, the length of the two arrays may not be the same. If the length of arr1 is greater than arr2, append the remaining elements of arr1 to the new array. If the length of arr2 is greater than arr1, append the re... | codefeedback |
Develop a Python code to extract all words from a sentence that begin with a specific letter, have a length greater than or equal to 3, and contain at least one vowel.
sentence = "I love coding in Python"
letter = "P" | codefeedback |
Construct an SQL query for fetching all rows from a table named "Employees" where the employees have been hired in the last 6 months and are currently active. Additionally, the query should also return the total count of active employees in each department and display it in descending order. However, there is a bug in ... | codefeedback |
Create a Ruby program that takes a group of strings and returns the number of strings longer than 5 characters. Additionally, for each string longer than 5 characters, convert all vowels to uppercase and consonants to lowercase in that string before counting it. Finally, return the sum of the lengths of all strings tha... | codefeedback |
Debug the following function.
def f(n):
i = 0
while i < n:
i+=1
if i % 5 == 0 and i % 7 == 0:
print(i)
#Difficulty Increased#
The function should now only print numbers that are divisible by both 5 and 7, and are also prime numbers. | codefeedback |
Write a JavaScript program to iterate through a 2D array, print each value, and calculate the sum of all values in the array.
array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Additional Instructions:
- You are not allowed to use any built-in array iteration methods such as forEach(), map(), reduce(), etc.
- You must use a ne... | codefeedback |
Write a regular expression that matches all English alphabets except for the letters 'a', 'e', 'i', 'o', and 'u'. | codefeedback |
Write a method to implement binary search using Java. Your implementation should also handle cases where the array is not sorted in ascending order. Additionally, you need to handle cases where the array contains duplicate elements. | codefeedback |
Write a program to calculate the Nth term of the Fibonacci sequence using dynamic programming. Implement the function `fibonacci(n: int) -> int` that takes in an integer `n` as a parameter and returns the Nth term of the Fibonacci sequence.
You can assume that `n` will be a positive integer.
You should implement a dy... | codefeedback |
Create an algorithm that can recognize handwritten characters in real-time from a live video stream, with a minimum accuracy of 95%. The algorithm must also be able to differentiate between uppercase and lowercase characters, and should be able to recognize characters from different languages such as English, Spanish, ... | codefeedback |
Write a generic code for traversing a binary tree in post-order and counting the number of nodes greater than a given value. Additionally, the code should return the sum of all the nodes greater than the given value. | codefeedback |
Create a responsive web page using HTML, CSS, and JavaScript where the font size of the content dynamically adjusts based on the screen size and the user's scrolling behavior. Additionally, implement a feature that allows the user to change the font size manually by clicking on a button or using a keyboard shortcut.
F... | codefeedback |
Create a machine learning model in Python using the given dataset that classifies the data into either 'positive' or 'negative'. The dataset consists of 1000 instances, where each instance has 10 features. The features are a combination of numerical, categorical, and textual data. Before training the model, you need to... | codefeedback |
Write a SQL query that demonstrates the use of a CROSS JOIN in a multi-table join scenario to retrieve data from five tables: Customers, Orders, Products, Employees, and Categories. Additionally, include a subquery to calculate the total revenue generated from each product category. | codefeedback |
Edit the following HTML code so that it displays a black, 100px border-radius circle. Additionally, make the circle rotate clockwise continuously at a speed of 1 rotation per second. However, the rotation should only start after the circle has been clicked by the user. | codefeedback |
Write a recursive function that calculates the factorial of a given number. However, the function should also handle large inputs, such as calculating the factorial of a number up to 1000. | codefeedback |
Suggest a way of sorting an array of integers A in descending order. The sorting algorithm should have a time complexity of O(n log n) and should be stable. Additionally, you are not allowed to use any built-in sorting functions or libraries. You are also not allowed to use any extra memory apart from the input array i... | codefeedback |
Identify the type of layout used in this HTML structure and explain how it can be implemented using CSS Grid, ensuring that the grid items are arranged in a complex overlapping pattern with specific grid lines and areas defined. | codefeedback |
Write a program that takes a list of integers as input and calculates the average of all the positive numbers in the list. Implement the solution using try and except blocks, and include an additional error handling mechanism to check for a specific type of error.
The program should:
1. Prompt the user to enter the e... | codefeedback |
Create a web page that utilizes HTML5 Canvas to display a real-time interactive 3D animation of a rotating cube. The cube should be rendered using WebGL and should respond to user input by rotating in the corresponding direction. The animation should be smooth and fluid, with no visible lag or delay. Additionally, the ... | codefeedback |
Create a program to generate the n-th Fibonacci number using recursion. The program should have a time complexity of O(2^n). | codefeedback |
Write a web scraper in Python to collect the data from the top 1000 IMDB movies, but only include movies released between 2010 and 2020 and with a rating above 8.5. Additionally, the scraper should also collect the names of the top 5 actors/actresses for each movie and store them in a separate file.
Note: You are not ... | codefeedback |
Extract all the strings that match the following regex pattern from a given text block which is in the format "name #number", where the name can be any alphanumeric characters and the number is a 4-digit integer. The extracted strings should be sorted in descending order based on the number. | codefeedback |
Identify the division of two numbers, where the first number is an integer N (1 ≤ N ≤ 10^6) and the second number is an integer M (1 ≤ M ≤ 10^6). The division should be performed using only bitwise operators and without using the division operator (/) or the modulo operator (%). | codefeedback |
Create a multi-dimensional array in Python where each element is a randomly generated integer between 1 and 100. The array should have dimensions of at least 10x10 and should be populated in a way that no two elements in the same row, column, or diagonal have the same value. Additionally, the array should be sorted in ... | codefeedback |
Complete the following JavaScript function so that it reads the string parameter and prints all the uppercase letters that are followed by a lowercase letter. The function should run in O(n) time complexity, where n is the length of the string. The space complexity should be O(1).
function print_uppercase_letters(str... | codefeedback |
Create a class in Java with three private fields, where each field is an array of integers with a length of n. The class should also have three public functions:
1. `void setValue(int fieldIndex, int elementIndex, int value)`: This function should set the value of the element at the specified `elementIndex` in the arr... | codefeedback |
Given an array of positive integers and a target value, modify the array such that each element is the multiplication of all the previous elements in the array and the target value. The resulting array should have the same length as the original array.
#Additional Instructions#
- You are not allowed to use division.
-... | codefeedback |
How do you test a web application using Selenium webdriver in a multi-browser environment, while implementing parallel test execution for Chrome, Firefox, and Safari browsers? Provide steps to set up and execute parallel tests for the given browsers. | codefeedback |
Suggest an improvement to make the code more efficient and implement it using a recursive function. | codefeedback |
Given a linked list of integers, find the maximum element in the list. Keep track of the second maximum element as well. Additionally, you need to find the index position of both the maximum and second maximum elements in the linked list.
# Example:
Input: 1 -> 2 -> 3 -> 4 -> 5
Output: Maximum element: 5, Second max... | codefeedback |
Write a program that takes a string and a character as input, and returns the number of occurrences of that character in the string. The program should also print the index positions of each occurrence of the character in the string, separated by a space. | codefeedback |
Suggest a way to change the following code so that it prints a pattern of asterisks in a pyramid shape without using any loops, and without using any built-in string manipulation functions.
Example:
*
***
*****
*******
********* | codefeedback |
Compute the median of the elements of the given list, but with the following constraints:
1. The list may contain duplicates, and they should be counted individually in the median calculation.
2. The median should be rounded to the nearest integer.
3. You are not allowed to use any built-in functions or libraries for m... | codefeedback |
Calculate the sum of all the even integers in the range of m to n (inclusive), where m and n are positive integers. Additionally, the program should check if the sum is a prime number and print a message indicating whether it is prime or not. m = 10, n = 20 | codefeedback |
Write a LINQ query in C# to select customers from the USA who have made at least 5 purchases in the last month and have a total purchase amount greater than $1000. Additionally, exclude customers who have made any purchases with a credit card that has expired in the last month. | codefeedback |
Suggest one line of code that should be added to the following function to make it more efficient.
Write a function called "search_prime_numbers" that takes in a positive integer "n" as a parameter. The function should find and print all prime numbers up to and including "n". A prime number is a number greater than 1 ... | codefeedback |
Write a program that prompts the user to enter a paragraph of text and then identifies all the email addresses in the given paragraph. The program should then extract the domain names from the email addresses and count the number of occurrences for each domain. Finally, the program should display the domain names along... | codefeedback |
Create a class called RandomGenerator that contains three methods:
1. The first method, called generateRandomNumber, should take in two parameters: a minimum value (min) and a maximum value (max). This method should generate and return a random number between the given range (inclusive). Implement a logic that ensures... | codefeedback |
Write a multi-threaded RabbitMQ consumer in Java to listen to a particular queue and process the messages concurrently.
Requirements:
1. The consumer should be able to handle a large number of incoming messages without blocking or slowing down the processing.
2. The consumer should use thread pooling to process the me... | codefeedback |
Implement the bottom up cut rod algorithm in Python, ensuring that the time complexity of your solution is O(n^2) and the space complexity is O(n). Additionally, you should optimize the algorithm to minimize the number of recursive calls made. | codefeedback |
Provide a function to implement an In-order Binary Tree traversal. However, the function should not use recursion or any stack data structure and should instead use a Morris traversal approach. | codefeedback |
Create a stored procedure in SQL to insert a new entry into a 'products' table. Additionally, ensure that the stored procedure checks for duplicate entries before inserting the new entry. If a duplicate entry is found, instead of inserting a new entry, update the existing entry with the new information. The stored proc... | codefeedback |
Use a template in HTML and JavaScript to create a table with 1000 columns and 1000 rows.
Additionally, each cell in the table should display a random number between 1 and 100.
The table should be dynamically generated using JavaScript, rather than hard-coding the HTML.
You are not allowed to use any JavaScript libra... | codefeedback |
Define a JavaScript class to store information about a circle, including its radius and coordinates of its center.
The class should have the following methods:
1. `getArea()`: Calculate and return the area of the circle.
2. `getCircumference()`: Calculate and return the circumference of the circle.
3. `getDiameter()`:... | codefeedback |
Generate the Fibonacci sequence up to a given number n and calculate the sum of the even numbers in the sequence. Additionally, find the product of the odd numbers in the sequence.
n = 15 | codefeedback |
How can you handle errors in Python by using try-except blocks and raising custom exceptions? Additionally, you should implement a logging mechanism to log the error messages and timestamps for each exception raised. | codefeedback |
Write a Python function that takes in a string and returns a new string with all uppercase letters converted to lowercase, and vice versa, without using the built-in `swapcase()` function. The function should preserve the original case of any non-alphabetic characters in the input string. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.